Amazon Selling Partner APIs official client library for PHP.

1.1.0 2025-05-05 07:35 UTC

This package is auto-updated.

Last update: 2025-05-05 07:36:33 UTC


README

Video Thumbnail

Click on the image to watch the video.

The Selling Partner API SDK for PHP enables you to easily connect your PHP application to Amazon's REST-based SP-API.

This SDK helps developers:

  • Authenticate with Amazon's Selling Partner API (SP-API)
  • Send and receive data using RESTful endpoints
  • Manage Amazon marketplace operations programmatically

Getting started

Credentials

Before you can use the SDK, you need to be registered as a Selling Partner API developer. If you haven't done that yet, please follow the instructions in the documentation. You also need to register your application to get valid credentials to call SP-API. If you haven't done that yet, please follow the instructions in the documentation. If you are already registered successfully, you can find instructions on how to view your credentials in the documentation.

Installation & Usage

Minimum Requirements

To run the SDK you need PHP 8.3 or higher.

Installation

Install the SDK via Composer:

composer require amzn-spapi/sdk

Manual Installation

By using the download files, composer dependencies are already installed. You only need to include autoload.php:

<?php
require_once('/path/to/OpenAPIClient-php/vendor/autoload.php');

Use the SDK

In order to call one of the APIs included in the Selling Partner API, you need to:

  • Configure credentials and marketplace ids. We provided a .env file to test the SDK in php/sdk/.env
  • Create an instance for a specific API (e.g. Orders API)
  • Call an operation
<?php
require_once(__DIR__ . '/vendor/autoload.php');

use SpApi\AuthAndAuth\LWAAuthorizationCredentials;
use SpApi\Configuration;
use SpApi\Api\orders\v0\OrdersV0Api;


// Set up LWA credentials
$lwaAuthorizationCredentials = new LWAAuthorizationCredentials([
"clientId" => "amzn1.application-**************",
"clientSecret" => "***********",
"refreshToken" => "***********",
"endpoint" => "https://api.amazon.com/auth/o2/token"
]);

//Initialize config
$config = new Configuration([], $lwaAuthorizationCredentials);

// Setting SP-API endpoint region
$config->setHost('https://sellingpartnerapi-na.amazon.com');

// Create a new HTTP client
$client = new GuzzleHttp\Client();

// Create an instance of the Orders Api
$api = new OrdersV0Api($config, $client);

try {
    // Call getOrders
    $result = $api->getOrders(
        $marketplace_ids = ['ATVPDKIKX0DER'],
        $created_after = '2025-01-01'
    );
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling OrderApi->getOrders: ', $e->getMessage(), PHP_EOL;
}

Built-in rate limiter

The SDK comes with a built-in rate limiter. In case you hit a certain rate limit, calling an operation will throw RateLimitExceededException. Catch this exception and handle it appropriately. By default, a standard rate limit configuration is applied. You can find the current rate limit configuration for each API on a dedicated page in the documention (e.g. for Listings Items API).

It is possible to disable the built-in rate limiter by setting rateLimiterEnabled to false when instantiating a API instance:

$api = new OrdersV0Api($config, $client, false);

It is also possible to override the default rate limit configuration. This has to be done after the API instance has been created and for each operation separately:

$rateLimitConfiguration = [
    'id' => 'spApi',
    'policy' => 'token_bucket',
    'limit' => 5, // capacity of bucket
    'rate' => [ // refill rate
        'interval' => '1 second',
        'amount' => 50
    ],
];

$factory = new RateLimiterFactory($rateLimitConfiguration, new InMemoryStorage());
$api->getOrderRateLimiter = $factory->create("<insert-unique-id>"); // Use unique id in create-method

Giving Feedback

Feedback and Contributions

Your feedback is invaluable in improving this SDK! You can contribute by:

Disclaimer