PHPackages                             hkonnet/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. hkonnet/selling-partner-api

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

hkonnet/selling-partner-api
===========================

PHP client for Amazon's Selling Partner API

3.2.1(4y ago)03.8k↓50%BSD-3-ClausePHPPHP &gt;=7.0

Since Feb 14Pushed 4y agoCompare

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

READMEChangelog (7)Dependencies (3)Versions (45)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/).

Sponsors
--------

[](#sponsors)

- [B&amp;L Consulting](http://www.blmc.group/)
- [Meteora Growth](http://www.meteoragrowth.com/)

Powering companies like...
--------------------------

[](#powering-companies-like)

- [Wizard Industries](https://wizard-industries.com)
- [Mendota Pet](https://mendotapet.com)
- [GLE Tech](https://gletech.com)

---

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 7/2/2021 ([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

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

[](#installation)

`composer require jlevers/selling-partner-api`

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://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/developer-guide/SellingPartnerApiDeveloperGuide.md#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://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/developer-guide/SellingPartnerApiDeveloperGuide.md#selling-partner-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.

### Example

[](#example)

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.

```
