wareon/amazon-sp-api-php

2.1.3 2021-04-21 12:13 UTC

This package is auto-updated.

Last update: 2024-09-17 18:08:15 UTC


README

这是一个用于新亚马逊销售合作伙伴API的PHP API绑定。

此库基于swagger-codegen的输出以及亚马逊提供的OpenAPI文件,并由贡献者进行了修改。

此包的目的是通过简单的composer包轻松开始使用亚马逊销售合作伙伴API。

要求

  • PHP >= 7.3
  • cURL 扩展
  • JSON 扩展
  • MBString 扩展

安装

只需通过composer要求此包

composer require clousale/amazon-sp-api-php

详细文档

您可以在docs/Api目录中找到此PHP库的详细文档(请注意:命名空间和其他类可能已更改)

您可以在官方亚马逊开发者网站上找到有关亚马逊销售合作伙伴API的一般信息。

示例

以下是一些简单的示例,仅用于展示如何开始调用API。

IAM 角色

当您在开发者配置文件中输入了IAM角色ARN时

<?php

require_once './vendor/autoload.php';

$options = [
    'refresh_token' => '', // Aztr|...
    'client_id' => '', // App ID from Seller Central, amzn1.sellerapps.app.cfbfac4a-......
    'client_secret' => '', // The corresponding Client Secret
    'region' => \ClouSale\AmazonSellingPartnerAPI\SellingPartnerRegion::$EUROPE, // or NORTH_AMERICA / FAR_EAST
    'access_key' => '', // Access Key of AWS IAM User, for example AKIAABCDJKEHFJDS
    'secret_key' => '', // Secret Key of AWS IAM User
    'endpoint' => \ClouSale\AmazonSellingPartnerAPI\SellingPartnerEndpoint::$EUROPE, // or NORTH_AMERICA / FAR_EAST
    'role_arn' => '', // AWS IAM Role ARN for example: arn:aws:iam::123456789:role/Your-Role-Name
];
$accessToken = \ClouSale\AmazonSellingPartnerAPI\SellingPartnerOAuth::getAccessTokenFromRefreshToken(
    $options['refresh_token'],
    $options['client_id'],
    $options['client_secret']
);
$assumedRole = \ClouSale\AmazonSellingPartnerAPI\AssumeRole::assume(
    $options['region'],
    $options['access_key'],
    $options['secret_key'],
    $options['role_arn'],
);
$config = \ClouSale\AmazonSellingPartnerAPI\Configuration::getDefaultConfiguration();
$config->setHost($options['endpoint']);
$config->setAccessToken($accessToken);
$config->setAccessKey($assumedRole->getAccessKeyId());
$config->setSecretKey($assumedRole->getSecretAccessKey());
$config->setRegion($options['region']);
$config->setSecurityToken($assumedRole->getSessionToken());
$apiInstance = new \ClouSale\AmazonSellingPartnerAPI\Api\CatalogApi($config);
$marketplace_id = 'A1PA6795UKMFR9';
$asin = 'B0002ZFTJA';

$result = $apiInstance->getCatalogItem($marketplace_id, $asin);
echo $result->getPayload()->getAttributeSets()[0]->getTitle(); // Never Gonna Give You Up [Vinyl Single]

IAM 用户

当您输入了用户ARN而不是角色ARN时,请使用此示例

<?php

require_once './vendor/autoload.php';

$options = [
    'refresh_token' => '', // Aztr|...
    'client_id' => '', // App ID from Seller Central, amzn1.sellerapps.app.cfbfac4a-......
    'client_secret' => '', // The corresponding Client Secret
    'region' => \ClouSale\AmazonSellingPartnerAPI\SellingPartnerRegion::$EUROPE, // or NORTH_AMERICA / FAR_EAST
    'access_key' => '', // Access Key of AWS IAM User, for example AKIAABCDJKEHFJDS
    'secret_key' => '', // Secret Key of AWS IAM User
    'endpoint' => \ClouSale\AmazonSellingPartnerAPI\SellingPartnerEndpoint::$EUROPE, // or NORTH_AMERICA / FAR_EAST
];
$accessToken = \ClouSale\AmazonSellingPartnerAPI\SellingPartnerOAuth::getAccessTokenFromRefreshToken(
    $options['refresh_token'],
    $options['client_id'],
    $options['client_secret']
);
$config = \ClouSale\AmazonSellingPartnerAPI\Configuration::getDefaultConfiguration();
$config->setHost($options['endpoint']);
$config->setAccessToken($accessToken);
$config->setAccessKey($options['access_key']);
$config->setSecretKey($options['secret_key']);
$config->setRegion($options['region']);
$apiInstance = new \ClouSale\AmazonSellingPartnerAPI\Api\CatalogApi($config);
$marketplace_id = 'A1PA6795UKMFR9';
$asin = 'B0002ZFTJA';

$result = $apiInstance->getCatalogItem($marketplace_id, $asin);
echo $result->getPayload()->getAttributeSets()[0]->getTitle(); // Never Gonna Give You Up [Vinyl Single]

待办事项

  • 实现测试
  • 改进文档

欢迎提出功能请求和拉取请求!

备注

如果您正在寻找完整的再定价和FBA报销解决方案,您可能想尝试ClouSale.com

感谢

感谢所有为这个包添加PR和工作的每个人。