sapientpro/ebay-browse-sdk-php

PHP SDK for Ebay Browse API

v1.0.0 2023-06-27 14:49 UTC

This package is not auto-updated.

Last update: 2024-11-18 17:23:32 UTC


README

Using the Browse API, you can create a rich selection of items for your buyers to browse with keyword and category searches.

  • API version: v1.18.4

Requirements

  • PHP 8.1 and later
  • ext-json and ext-curl extensions enabled

Installation & Usage

Install the package using composer:

composer require sapientpro/ebay-browse-sdk-php

Getting Started

Please follow the installation procedure and then run the following:

<?php
use SapientPro\EbayBrowseSDK\Configuration;
use SapientPro\EbayBrowseSDK\Api\ItemApi;
use SapientPro\EbayBrowseSDK\Models\CompatibilityPayload;

// Configure OAuth2 access token for authorization: api_auth
$config = Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');

$apiInstance = new ItemApi(
config: $config
);
// you can create and fill a Model class that implements EbayModelInterface using fromArray() method
// exception will be thrown if a property does not exist in the model class
$body = CompatibilityPayload::fromArray([]);

try {
$result = $apiInstance->checkCompatibility($body);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling InventoryItemApi->bulkCreateOrReplaceInventoryItem: ', $e->getMessage(), PHP_EOL;
}

Creating Models

Some SDK methods require $body variable as a parameter. It refers to a Model class that implements EbayModelInterface. There are several ways to create a Model class:

fromArray()

You can create a Model class using fromArray() method. It will throw an exception if a property does not exist in the model class.

If the model has a property of type that implements EbayModelInterface, you must create an instance of that class using fromArray() method. In this example, the property price is of type ConvertedAmount that also implements EbayModelInterface.

Item::fromArray([
    'price' => ConvertedAmount::fromArray([
        'value' => '6.90',
        'currency' => CurrencyCodeEnum::USD
    )]
])

fromPlainArray()

It is also possible to create a Model from plain associative array. The previous example can be rewritten as follows:

Item::fromPlainArray([
    'price' => [
        'value' => '6.90',
        'currency' => CurrencyCodeEnum::USD
    ]
])

fromJson()

It is also possible to create a Model from JSON string.

Item::fromJson('{"price": {"value": "6.90", "currency": "USD"}}')

Documentation for API Endpoints

All URIs are relative to https://api.ebay.com/buy/browse/v1

Documentation for Models

Authorization

api_auth