amorvan/ebay-inventory-sdk-php

PHP SDK for Ebay Inventory API

v1.0.0 2024-03-10 21:23 UTC

This package is auto-updated.

Last update: 2024-09-10 22:33:13 UTC


README

库存API用于创建和管理库存,然后在eBay市场上发布和管理此库存。此API中还有一些方法可以将有资格的、活动的eBay列表转换为库存API模型。

此PHP包由Swagger Codegen项目自动生成

  • API版本:1.16.2
  • 构建包:io.swagger.codegen.v3.generators.php.PhpClientCodegen

要求

  • PHP 8.1及更高版本
  • 启用ext-curl和ext-json扩展

安装与使用

使用composer安装此包

composer require sapientpro/ebay-account-sdk-php

入门指南

请按照安装过程进行操作,然后运行以下命令

<?php
use SapientPro\EbayInventorySDK\Configuration;
use SapientPro\EbayInventorySDK\Api\InventoryItemApi;
use SapientPro\EbayInventorySDK\Models\BulkInventoryItem;

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

$apiInstance = new InventoryItemApi(
    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 = BulkInventoryItem::fromArray([]);

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

注意:某些方法需要$contentLanguage参数。它的值应该是字符串类型,对应于LocaleEnum情况,但应以短横线分隔:LocaleEnum::en_US -> 'en-US'

创建模型

某些SDK方法需要$body变量作为参数。它指的是实现了EbayModelInterface的Model类。创建Model类有几种方法

fromArray()

您可以使用fromArray()方法创建Model类。如果模型类中不存在属性,它将抛出异常。

如果模型有实现EbayModelInterface类型的属性,您必须使用fromArray()方法创建该类的实例。在此示例中,属性price是类型为ConvertedAmount的,它也实现了EbayModelInterface。

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

fromPlainArray()

也可以从纯关联数组创建Model。前面的示例可以重写如下

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

fromJson()

还可以从JSON字符串创建Model。

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

API端点文档

所有URI相对于https://api.ebay.com/sell/inventory/v1

模型文档

授权

api_auth