PHPackages                             weboptic/amzed-selling-partner-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. weboptic/amzed-selling-partner-api

ActiveLibrary[HTTP &amp; Networking](/categories/http)

weboptic/amzed-selling-partner-api
==================================

PHP client for Amazon's Selling Partner API

v7.4.3(6mo ago)06BSD-3-ClausePHPPHP &gt;=8.2

Since Feb 14Pushed 3mo agoCompare

[ Source](https://github.com/weboptic/amzed-selling-partner-api)[ Packagist](https://packagist.org/packages/weboptic/amzed-selling-partner-api)[ RSS](/packages/weboptic-amzed-selling-partner-api/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (13)Versions (140)Used By (0)

 [ ![Highside Labs logo](https://github.com/highsidelabs/.github/raw/main/images/logo.png?raw=true) ](https://highsidelabs.co)

 [![Total downloads](https://camo.githubusercontent.com/e6111a68742b13e232734bd4d08abad1fb5ee025e803ea660363438dd97f2c4a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6c65766572732f73656c6c696e672d706172746e65722d6170692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jlevers/selling-partner-api) [![Latest stable version](https://camo.githubusercontent.com/362b8687fab4c3c7ebf7ce2671ceb5f994a9e51083de2ded9524663c0d7065d0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6c65766572732f73656c6c696e672d706172746e65722d6170692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jlevers/selling-partner-api) [![License](https://camo.githubusercontent.com/d7c5bd30f0a2f35971077402578a131ac701b1372d5cc13dcd9a5ef7ef09718e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a6c65766572732f73656c6c696e672d706172746e65722d6170692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jlevers/selling-partner-api)

Selling Partner API for PHP
---------------------------

[](#selling-partner-api-for-php)

A PHP library for connecting to Amazon's [Selling Partner API](https://github.com/amzn/selling-partner-api-docs/).

Warning

Amazon has deprecated [most listings-related XML and flat-file feeds](https://developer-docs.amazon.com/sp-api/docs/sp-api-release-notes#feeds). I built an [**Amazon feed converter**](https://tools.highsidelabs.co) tool for easily converting the deprecated feeds to the newer `JSON_LISTINGS_FEED` format with a few lines of code. Read the full documentation [here](https://docs.highsidelabs.co/feed-transformer).

### Related packages

[](#related-packages)

- [`highsidelabs/laravel-spapi`](https://github.com/highsidelabs/laravel-spapi): A [Laravel](https://laravel.com) wrapper for this package that makes SP API integration in Laravel projects quick and easy. I also developed a [Laravel SP API starter project](https://tools.highsidelabs.co/starter-kit) to make developing SP API apps on Laravel as easy as possible.
- [`highsidelabs/amazon-business-api`](https://github.com/highsidelabs/amazon-business-api): A PHP library for Amazon's [Business API](https://developer-docs.amazon.com/amazon-business/docs).
- [`highsidelabs/walmart-api`](https://github.com/highsidelabs/walmart-api-php): A PHP library for [Walmart's seller and supplier APIs](https://developer.walmart.com), including the Marketplace, Drop Ship Vendor, Content Provider, and Warehouse Supplier APIs.
- [`shipstream/fedex-rest-sdk`](https://github.com/shipstream/fedex-rest-php-sdk): A PHP library for interacting with FedEx's REST APIs, built by me on behalf of [ShipStream](https://shipstream.io).

---

If you've found any of my packages useful, please consider [becoming a Sponsor](https://github.com/sponsors/jlevers), or making a one-time donation via the button below. I appreciate any and all support! Keeping open source projects alive is a community effort.

 [![Donate to Jesse Evers](https://camo.githubusercontent.com/e1ff554a09e8e92bef25abc553ff05b88f45afd695877cf12f3a46558ef65b2e/68747470733a2f2f7777772e70617970616c6f626a656374732e636f6d2f656e5f55532f692f62746e2f62746e5f646f6e61746543435f4c472e676966)](https://www.paypal.com/donate?business=EL4PRLAEMGXNQ&currency_code=USD)

### Sponsored by **[Tesmo](https://tesmollc.com)**.

[](#sponsored-by-tesmo)

### Sponsored by **[Highside Labs](https://tools.highsidelabs.co/starter-kit)**. Get started with SP API development on Laravel in minutes.

[](#sponsored-by-highside-labs-get-started-with-sp-api-development-on-laravel-in-minutes)

---

Note

If you're looking for the documentation for v5 of this package, you can find it [here](https://github.com/jlevers/selling-partner-api/tree/v5.0).

Features
--------

[](#features)

- Supports all Selling Partner API operations (for Sellers and Vendors) as of 12/6/2025
- Automatically generates Restricted Data Tokens for all calls that require them -- no extra calls to the Tokens API needed
- Includes a [`Document` helper class](#uploading-and-downloading-documents) for uploading and downloading feed/report documents
- Can handle the end-to-end OAuth flow, from building authorization URLs to converting authorization codes into refresh tokens

Installation
------------

[](#installation)

`composer require jlevers/selling-partner-api`

Contributing
------------

[](#contributing)

See [CONTRIBUTING.md](CONTRIBUTING.md) for details.

Table of Contents
-----------------

[](#table-of-contents)

Check out the [Getting Started](#getting-started) section below for a quick overview.

This README is divided into several sections:

- [Setup](#setup)
    - [Configuration options](#configuration-options)
- [Debugging](#debugging)
- [Working with responses](#working-with-responses)
- [Working with DTOs](#working-with-dtos)
- [Supported API segments](#supported-api-segments)
    - [Seller APIs](#seller-apis)
    - [Vendor APIs](#vendor-apis)
- [Restricted operations](#restricted-operations)
- [Uploading and downloading documents](#uploading-and-downloading-documents)
    - [Downloading a report document](#downloading-a-report-document)
    - [Uploading a feed document](#uploading-a-feed-document)
    - [Downloading a feed result document](#downloading-a-feed-result-document)
- [OAuth](#oauth)
    - [Building authorization URIs](#building-authorization-uris)
    - [Generating a refresh token from an authorization code](#generating-a-refresh-token-from-an-authorization-code)
- [Naming conventions](#naming-conventions)

Getting Started
---------------

[](#getting-started)

### Prerequisites

[](#prerequisites)

To get started, you need an approved Selling Partner API developer account, and SP API application credentials, which you can get by creating a new SP API application in Seller Central.

### Setup

[](#setup)

The [`SellingPartnerApi`](https://github.com/jlevers/selling-partner-api/blob/main/src/SellingPartnerApi.php) class acts as a factory to generate Seller and Vendor API connector instances. Its `seller()` and `vendor()` methods each take a set of identical (and optionally, named) parameters. Its basic usage looks like this:

```
use SellingPartnerApi\SellingPartnerApi;
use SellingPartnerApi\Enums\Endpoint;

$connector = SellingPartnerApi::seller(
    clientId: 'amzn1.application-oa2-client.asdfqwertyuiop...',
    clientSecret: 'amzn1.oa2-cs.v1.1234567890asdfghjkl...',
    refreshToken: 'Atzr|IwEBIA...',
    endpoint: Endpoint::NA,  // Or Endpoint::EU, Endpoint::FE, Endpoint::NA_SANDBOX, etc.
);
```

Note

Older versions of the Selling Partner API used AWS IAM credentials to authenticate, and so this library had additional AWS configuration options. If you're upgrading from an older version of this library and are confused about what to do with your AWS creds, you can just ignore them. The SP API no longer authenticates via AWS IAM roles or users.

Now you have a Selling Partner API connector instance, and you can start making calls to the API. The connector instance has methods for each of the API segments (e.g., `sellers`, `orders`, `fba-inbound`), and you can access them like so:

```
$ordersApi = $connector->ordersV0();
$response = $ordersApi->getOrders(
    createdAfter: new DateTime('2024-01-01'),
    marketplaceIds: ['ATVPDKIKX0DER'],
);
```

Once you have a response, you can either access the raw JSON response via `$response->json()`, or you can automatically parse the response into a DTO by calling `$response->dto()`. Once the response is turned into a DTO, you can access the data via the DTO's properties. For instance, you can get the first order's purchase date like so:

```
$dto = $response->dto();
$purchaseDate = $dto->payload->orders[0]->purchaseDate;
```

See the [Working with responses](#working-with-responses) section for more details on how to work with responses, and [Working with DTOs](#working-with-dtos) for more details on how to use DTOs.

##### Configuration options

[](#configuration-options)

The `SellingPartnerApi::seller()` and `SellingPartnerApi::vendor()` builder methods accept the following arguments:

- `clientId (string)`: Required. The LWA client ID of the SP API application to use to execute API requests.
- `clientSecret (string)`: Required. The LWA client secret of the SP API application to use to execute API requests.
- `refreshToken (string)`: The LWA refresh token of the SP API application to use to execute API requests. Required, unless you're only using [grantless operations](https://developer-docs.amazon.com/sp-api/docs/grantless-operations), in which case you can pass a dummy string like `'grantless'`.
- `endpoint`: Required. An instance of the [`SellingPartnerApi\Enums\Endpoint` enum](https://github.com/jlevers/selling-partner-api/blob/main/src/Enums/Endpoint.php). Primary endpoints are `Endpoint::NA`, `Endpoint::EU`, and `Endpoint::FE`. Sandbox endpoints are `Endpoint::NA_SANDBOX`, `Endpoint::EU_SANDBOX`, and `Endpoint::FE_SANDBOX`.
- `dataElements (array)`: Optional. An array of data elements to pass to restricted operations. See the [Restricted operations](#restricted-operations) section for more details.
- `delegatee (string)`: Optional. The application ID of a delegatee application to generate RDTs on behalf of.
- `authenticationClient (GuzzleHttp\Client)`: Guzzle client instance that will be used to generate the access token from the refresh token. If not provided, the default Saloon Guzzle client will be used.
- `cache (SellingPartnerApi\Contracts\TokenCache)`: A cache interface instance that will be used to cache access tokens. If not provided, a basic in-memory cache will be used. If set to `null`, caching will be disabled.

### Debugging

[](#debugging)

To get detailed debugging output, you can take advantage of [Saloon's debugging hooks](https://docs.saloon.dev/digging-deeper/debugging). This package is built on top of Saloon, so anything that works in Saloon will work here. For instance, to debug requests:

```
use Psr\Http\Message\RequestInterface;
use Saloon\Http\PendingRequest;
use SellingPartnerApi\SellingPartnerApi;

$connector = SellingPartnerApi::seller(
    clientId: 'amzn1.application-oa2-client.asdfqwertyuiop...',
    clientSecret: 'amzn1.oa2-cs.v1.1234567890asdfghjkl...',
    refreshToken: 'Atzr|IwEBIA...',
    endpoint: Endpoint::NA,
);

$connector->debugRequest(
    function (PendingRequest $pendingRequest, RequestInterface $psrRequest) {
        var_dump($pendingRequest->headers()->all(), $psrRequest);
    }
);
```

Then make requests with the connector as usual, and you'll hit the closure above every time a request is fired. You can also debug responses in a similar fashion – check out the [Saloon docs](https://docs.saloon.dev/digging-deeper/debugging#debugging-responses) for more details.

If you want to output your debug data to a file, you can do so with the `SellingPartnerApi::debugRequestToFile()`, `SellingPartnerApi::debugResponseToFile()`, and `SellingPartnerApi::debugToFile()` methods. These methods all take an `$outputPath` argument and an optional `$die` argument.

Working with responses
----------------------

[](#working-with-responses)

As mentioned earlier, all endpoint methods return an instance of `Saloon\Response`. You can access the raw JSON response via `$response->json()`, or you can automatically parse the response into a DTO by calling `$response->dto()`. Once the response is turned into a DTO, you can access the data via the DTO's properties (described below). Saloon's [response documentation](https://docs.saloon.dev/the-basics/responses) gives a comprehensive guide to working with Saloon responses, including retrieving headers, status, and more.

Working with DTOs
-----------------

[](#working-with-dtos)

Some methods take DTOs as parameters. For instance, the `confirmShipment` method in the Orders API takes a `ConfirmShipmentRequest` DTO as a parameter. You can call `confirmShipment` like so:

```
