sapientpro/ebay-inventory-sdk-php

Ebay Inventory API 的 PHP SDK

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

This package is not auto-updated.

Last update: 2024-09-23 16:21:42 UTC


README

库存 API 用于创建和管理库存,然后在 eBay 市场上发布和管理此库存。此 API 中还有将符合条件的、活跃的 eBay 列表转换为库存 API 模型的方法。

此 PHP 包由 Swagger Codegen 项目自动生成(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 的模型类。有几种创建模型类的方法

fromArray()

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

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

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

fromPlainArray()

您还可以从普通关联数组创建模型。前面的示例可以重写如下

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

fromJson()

您还可以从 JSON 字符串创建模型。

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

API 端点文档

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

模型文档

授权

api_auth