PHPackages                             hashhesh/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. [API Development](/categories/api)
4. /
5. hashhesh/selling-partner-api

ActiveLibrary[API Development](/categories/api)

hashhesh/selling-partner-api
============================

PHP client for Amazon's Selling Partner API

01PHP

Since Dec 29Pushed 3y agoCompare

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

READMEChangelogDependenciesVersions (2)Used By (0)

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/).

[![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)

[![Highside Labs Logo](https://camo.githubusercontent.com/b60b3c7563725611b4f6d071aad6cd1facbf5373c07d5b09d87252e8f61d6039/68747470733a2f2f68696768736964656c6162732e636f2f7374617469632f66617669636f6e732f66617669636f6e2e706e67)](https://highsidelabs.co)**This package is developed and maintained as part of [Highside Labs](https://highsidelabs.co). If you need support integrating with Amazon's (or any other e-commerce platform's) APIs, we're happy to help! Shoot us an email at . We'd love to hear from you :)**If you've found this library 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 you can provide!

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

---

Features
--------

[](#features)

- Supports all Selling Partner API operations (for Sellers and Vendors) as of 11/13/2022 ([see here](#supported-api-segments) for links to documentation for all calls)
- Supports applications made with both IAM user and IAM role ARNs ([docs](#setup))
- 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

Sponsors
--------

[](#sponsors)

- **[Tesmo](https://tesmollc.com)**

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

[](#installation)

`composer require jlevers/selling-partner-api`

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)
- [Examples](#examples)
- [Debug mode](#debug-mode)
- [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)
- [Working with model classes](#working-with-model-classes)
- [Response headers](#response-headers)
- [Custom request authorization](#custom-authorization-signer)
- [Custom request signing](#custom-request-signer)

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

[](#getting-started)

### Prerequisites

[](#prerequisites)

You need a few things to get started:

- A Selling Partner API developer account
- An AWS IAM user or role configured for use with the Selling Partner API
- A Selling Partner API application

If you're looking for more information on how to set those things up, check out [this blog post](https://jesseevers.com/selling-partner-api-access/). It provides a detailed walkthrough of the whole setup process.

### Setup

[](#setup)

The [`Configuration`](https://github.com/jlevers/selling-partner-api/blob/main/lib/Configuration.php) constructor takes a single argument: an associative array with all the configuration information that's needed to connect to the Selling Partner API:

```
$config = new SellingPartnerApi\Configuration([
    "lwaClientId" => "",
    "lwaClientSecret" => "",
    "lwaRefreshToken" => "",
    "awsAccessKeyId" => "",
    "awsSecretAccessKey" => "",
    // If you're not working in the North American marketplace, change
    // this to another endpoint from lib/Endpoint.php
    "endpoint" => SellingPartnerApi\Endpoint::NA,
]);
```

If you created your Selling Partner API application using an IAM role ARN instead of a user ARN, pass that role ARN in the configuration array:

```
$config = new SellingPartnerApi\Configuration([
    "lwaClientId" => "",
    "lwaClientSecret" => "",
    "lwaRefreshToken" => "",
    "awsAccessKeyId" => "",
    "awsSecretAccessKey" => "",
    // If you're not working in the North American marketplace, change
    // this to another endpoint from lib/Endpoint.php
    "endpoint" => SellingPartnerApi\Endpoint::NA,
    "roleArn" => "",
]);
```

Getter and setter methods exist for the `Configuration` class's `lwaClientId`, `lwaClientSecret`, `lwaRefreshToken`, `awsAccessKeyId`, `awsSecretAccessKey`, and `endpoint` properties. The methods are named in accordance with the name of the property they interact with: `getLwaClientId`, `setLwaClientId`, `getLwaClientSecret`, etc.

`$config` can then be passed into the constructor of any `SellingPartnerApi\Api\*Api` class. See the `Example` section for a complete example.

##### Configuration options

[](#configuration-options)

The array passed to the `Configuration` constructor accepts the following keys:

- `lwaClientId (string)`: Required. The LWA client ID of the SP API application to use to execute API requests.
- `lwaClientSecret (string)`: Required. The LWA client secret of the SP API application to use to execute API requests.
- `lwaRefreshToken (string)`: The LWA refresh token of the SP API application to use to execute API requests. Required, unless you're only using the `Configuration` instance to call [grantless operations](https://developer-docs.amazon.com/amazon-shipping/docs/grantless-operations).
- `awsAccessKeyId (string)`: Required. AWS IAM user Access Key ID with SP API ExecuteAPI permissions.
- `awsSecretAccessKey (string)`: Required. AWS IAM user Secret Access Key with SP API ExecuteAPI permissions.
- `endpoint (array)`: Required. An array containing a `url` key (the endpoint URL) and a `region` key (the AWS region). There are predefined constants for these arrays in [`lib/Endpoint.php`](https://github.com/jlevers/selling-partner-api/blob/main/lib/Endpoint.php): (`NA`, `EU`, `FE`, and `NA_SANDBOX`, `EU_SANDBOX`, and `FE_SANDBOX`. See [here](https://developer-docs.amazon.com/amazon-shipping/docs/sp-api-endpoints) for more details.
- `accessToken (string)`: An access token generated from the refresh token.
- `accessTokenExpiration (int)`: A Unix timestamp corresponding to the time when the `accessToken` expires. If `accessToken` is given, `accessTokenExpiration` is required (and vice versa).
- `onUpdateCredentials (callable|Closure)`: A callback function to call when a new access token is generated. The function should accept a single argument of type [`SellingPartnerApi\Credentials`](https://github.com/jlevers/selling-partner-api/blob/main/lib/Credentials.php).
- `roleArn (string)`: If you set up your SP API application with an AWS IAM role ARN instead of a user ARN, pass that ARN here.
- `authenticationClient (GuzzleHttp\ClientInterface)`: Optional `GuzzleHttp\ClientInterface` object that will be used to generate the access token from the refresh token
- `tokensApi (SellingPartnerApi\Api\TokensApi)`: Optional `SellingPartnerApi\Api\TokensApi` object that will be used to fetch Restricted Data Tokens (RDTs) when you call a [restricted operation](https://developer-docs.amazon.com/sp-api/docs/tokens-api-use-case-guide)
- `authorizationSigner (SellingPartnerApi\Contract\AuthorizationSignerContract)`: Optional `SellingPartnerApi\Contract\AuthorizationSignerContract` implementation. See [Custom Authorization Signer](#custom-authorization-signer) section
- `requestSigner (SellingPartnerApi\Contract\RequestSignerContract)`: Optional `SellingPartnerApi\Contract\RequestSignerContract` implementation. See [Custom Request Signer](#custom-request-signer) section.

### Examples

[](#examples)

This example assumes you have access to the `Seller Insights` Selling Partner API role, but the general format applies to any Selling Partner API request.

```
