PHPackages                             zero-to-prod/spapi - 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. zero-to-prod/spapi

ActiveLibrary[API Development](/categories/api)

zero-to-prod/spapi
==================

A PHP client library for Amazon's Selling Partner API.

v3.1.0(1y ago)13MITPHPPHP &gt;=7.1CI passing

Since Feb 2Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/zero-to-prod/spapi)[ Packagist](https://packagist.org/packages/zero-to-prod/spapi)[ Docs](https://github.com/zero-to-prod/spapi)[ Fund](https://github.com/sponsors/zero-to-prod)[ RSS](/packages/zero-to-prod-spapi/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (17)Used By (0)

Zerotoprod\\Spapi
=================

[](#zerotoprodspapi)

[![](art/logo.png)](art/logo.png)

[![Repo](https://camo.githubusercontent.com/9a90a3efeee26aed7d7f2feee9cd84566a26f9c362cc773b184d076210906e1c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6769746875622d677261793f6c6f676f3d676974687562)](https://github.com/zero-to-prod/spapi)[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/ee702b8183a72b40ced0e92577d129e2616610672b110b8d5b7b9eb427aee0f6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7a65726f2d746f2d70726f642f73706170692f746573742e796d6c3f6c6162656c3d74657374)](https://github.com/zero-to-prod/spapi/actions)[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/11d7fe9ba46c94d5adc0e1f379b31f23f6418f907fcbca5ffb6a9bed81abb0e6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7a65726f2d746f2d70726f642f73706170692f6261636b77617264735f636f6d7061746962696c6974792e796d6c3f6c6162656c3d6261636b77617264735f636f6d7061746962696c697479)](https://github.com/zero-to-prod/spapi/actions)[![Packagist Downloads](https://camo.githubusercontent.com/e6abfb80ea068e5bbc7598cf2df1d1b888b13ef59aa6ddc7c81cafad246b9c02/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a65726f2d746f2d70726f642f73706170693f636f6c6f723d626c7565)](https://packagist.org/packages/zero-to-prod/spapi/stats)[![php](https://camo.githubusercontent.com/8e510b6744cf742f492b3b1d7793fef6f379f0b99f5b30cf73efd4714096e14f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7a65726f2d746f2d70726f642f73706170692e7376673f636f6c6f723d707572706c65)](https://packagist.org/packages/zero-to-prod/spapi/stats)[![Packagist Version](https://camo.githubusercontent.com/06d4974c240eecb5ebe348cb4de3570df629872f92f1dbce5c49a2e1cc026aa9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a65726f2d746f2d70726f642f73706170693f636f6c6f723d663238643161)](https://packagist.org/packages/zero-to-prod/spapi)[![License](https://camo.githubusercontent.com/768ada6bfc7297e180aaff9268d05a19d4a78efb788bfa71b0cdcb0acf560db2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7a65726f2d746f2d70726f642f73706170693f636f6c6f723d70696e6b)](https://github.com/zero-to-prod/spapi/blob/main/LICENSE.md)[![wakatime](https://camo.githubusercontent.com/aeede219e0910f6ef75935c56d40a387cbedc3b50a0685c1c83ade55ba43c161/68747470733a2f2f77616b6174696d652e636f6d2f62616467652f6769746875622f7a65726f2d746f2d70726f642f73706170692e737667)](https://wakatime.com/badge/github/zero-to-prod/spapi)[![Hits-of-Code](https://camo.githubusercontent.com/3df0175a55b1c5ea2292663097bb5b007ac9fc6c176457bd7dee5ba55b8c1ecf/68747470733a2f2f686974736f66636f64652e636f6d2f6769746875622f7a65726f2d746f2d70726f642f73706170693f6272616e63683d6d61696e)](https://hitsofcode.com/github/zero-to-prod/spapi/view?branch=main)

Contents
--------

[](#contents)

- [Introduction](#introduction)
- [Requirements](#requirements)
- [Installation](#installation)
- [Documentation Publishing](#documentation-publishing)
    - [Automatic Documentation Publishing](#automatic-documentation-publishing)
- [Authentication](#authentication)
    - [Refresh Token](#refresh-token)
    - [Client Credentials](#client-credentials)
    - [Restricted Data Token](#restricted-data-token)
- [Orders Api](#orders-api)
    - [getOrders](#getorders)
    - [getOrder](#getorder)
    - [getOrderBuyerInfo](#getorderbuyerinfo)
    - [getOrderAddress](#getorderaddress)
    - [getOrderItems](#getorderitems)
- [Testing](#testing)
    - [Basic Testing](#basic-testing)
    - [Testing with Authentication Flow](#testing-with-authentication-flow)
- [Examples](#examples)
    - [Get an order with a Restricted Data Token](#get-an-order-with-a-restricted-data-token)
- [Local Development](./LOCAL_DEVELOPMENT.md)
- [Contributing](#contributing)

Introduction
------------

[](#introduction)

A PHP client library for Amazon's Selling Partner API.

Requirements
------------

[](#requirements)

- PHP 7.1 or higher.

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

[](#installation)

Install `Zerotoprod\Spapi` via [Composer](https://getcomposer.org/):

```
composer require zero-to-prod/spapi
```

This will add the package to your project's dependencies and create an autoloader entry for it.

Documentation Publishing
------------------------

[](#documentation-publishing)

You can publish this README to your local documentation directory.

This can be useful for providing documentation for AI agents.

This can be done using the included script:

```
# Publish to default location (./docs/zero-to-prod/spapi)
vendor/bin/zero-to-prod-spapi

# Publish to custom directory
vendor/bin/zero-to-prod-spapi /path/to/your/docs
```

### Automatic Documentation Publishing

[](#automatic-documentation-publishing)

You can automatically publish documentation by adding the following to your `composer.json`:

```
{
    "scripts": {
        "post-install-cmd": [
            "zero-to-prod-spapi"
        ],
        "post-update-cmd": [
            "zero-to-prod-spapi"
        ]
    }
}
```

Authentication
--------------

[](#authentication)

### Refresh Token

[](#refresh-token)

Use this for calling operations that require authorization from a selling partner. All operations that are not grantless operations require authorization from a selling partner. When specifying this value, include the rrefresh\_token parameter.

```
use Zerotoprod\Spapi\Lwa;
use Zerotoprod\SpapiLwa\SpapiLwa;

$response = SpapiLwa::from(
    'amzn1.application-oa2-client.xxx', // client_id
    'amzn1.oa2-cs.v1.xxx'               // client_secret
)->refreshToken('refresh_token');       // The LWA refresh token. Get this value when the selling partner authorizes your application

$access_token = $response['response']['access_token'];
```

### Client Credentials

[](#client-credentials)

Use this for calling grantless operations. When specifying this value, include the scope parameter.

```
use Zerotoprod\Spapi\Lwa;
use Zerotoprod\SpapiLwa\SpapiLwa;

$response = SpapiLwa::from(
    'amzn1.application-oa2-client.xxx', // client_id
    'amzn1.oa2-cs.v1.xxx',              // client_secret
)->clientCredentials('scope');

$access_token = $response['response']['access_token'];
```

### Restricted Data Token

[](#restricted-data-token)

Use the access token received from [Login With Amazon](#refresh-token);

```
use Zerotoprod\Spapi\Tokens;
use \Zerotoprod\SpapiRdt\SpapiRdt;

// Use the SpapiRdt API to get an RDT (Restricted Data Token)
$response = SpapiRdt::from(
    'access_token',                     // Access token received from LWA
    'amzn1.sp.solution.xxx'             // Target Application
)
    ->orders()
    ->getOrder(
        '123-1234567-1234567',           // Amazon Order Id
        ['buyerInfo', 'shippingAddress'] // Restricted Data Elements to Access
);

$access_token = $response['response']['restrictedDataToken'];
```

Spapi
-----

[](#spapi)

Instantiate the Spapi from an `access_token` generated from [Login With Amazon](#refresh-token) or a [Restricted Data Token](#restricted-data-token)

```
use Zerotoprod\Spapi\Spapi;

$Spapi = Spapi::from($access_token);
```

Orders Api
----------

[](#orders-api)

Programmatically retrieve order information.

Use the Orders Selling Partner API to programmatically retrieve order information. With this API, you can develop fast, flexible, and custom applications to manage order synchronization, perform order research, and create demand-based decision support tools.

### getOrders

[](#getorders)

Returns orders that are created or updated during the specified time period. If you want to return specific types of orders, you can apply filters to your request. NextToken doesn't affect any filters that you include in your request; it only impacts the pagination for the filtered orders response.

```
use Zerotoprod\Spapi\Spapi;

// Access the orders api and get orders.
$Orders = Spapi::from($access_token)
    ->orders()
    ->getOrders(
      ['MarketplaceIds']
      'CreatedAfter'
      'CreatedBefore'
      'LastUpdatedAfter'
      'LastUpdatedBefore'
      '[OrderStatuses']
      ['FulfillmentChannels']
      ['PaymentMethods']
      'BuyerEmail'
      'SellerOrderId'
      MaxResultsPerPage
      ['EasyShipShipmentStatuses']
      ['ElectronicInvoiceStatuses']
      'NextToken'
      ['AmazonOrderIds']
      'ActualFulfillmentSupplySourceId'
      'IsISPU'
      'StoreChainStoreId'
      'EarliestDeliveryDateBefore'
      'EarliestDeliveryDateAfter'
      'LatestDeliveryDateBefore'
      'LatestDeliveryDateAfter'
      ['curl_options'],
);

// Access the orders.
echo $Orders['response']['payload']['Orders'][0]['AmazonOrderId']

// Access errors.
echo $Orders['response']['errors']['code'];
```

### getOrder

[](#getorder)

Returns the order that you specify.

```
use Zerotoprod\Spapi\Spapi;

$Order = Spapi::from($access_token)
    ->orders()
    ->getOrder('111-5803802-7417822', ['curl_options']);

// Access the order.
echo $Order['response']['payload']['AmazonOrderId'];

// Access errors.
echo $Order['response']['errors']['code'];
```

### getOrderBuyerInfo

[](#getorderbuyerinfo)

Returns buyer information for the order that you specify.

```
use Zerotoprod\Spapi\Spapi;

$OrderBuyerInfo = Spapi::from($access_token)
    ->orders()
    ->getOrderBuyerInfo('111-5803802-7417822', ['curl_options']);

// Access the buyer info.
echo $OrderBuyerInfo['response']['payload']['BuyerName'];

// Access errors.
echo $OrderBuyerInfo['response']['errors']['code'];
```

### getOrderAddress

[](#getorderaddress)

Retrieves the shipping address for the specified order

```
use Zerotoprod\Spapi\Spapi;

$OrderBuyerInfo = Spapi::from($access_token)
    ->orders()
    ->getOrderAddress('111-5803802-7417822', ['curl_options']);

// Access the buyer info.
echo $OrderBuyerInfo['response']['payload']['BuyerName'];

// Access errors.
echo $OrderBuyerInfo['response']['errors']['code'];
```

### getOrderItems

[](#getorderitems)

Returns detailed order item information for the order that you specify. If NextToken is provided, it's used to retrieve the next page of order items.

Note: When an order is in the Pending state (the order has been placed but payment has not been authorized), the getOrderItems operation does not return information about pricing, taxes, shipping charges, gift status or promotions for the order items in the order. After an order leaves the Pending state (this occurs when payment has been authorized) and enters the Unshipped, Partially Shipped, or Shipped state, the getOrderItems operation returns information about pricing, taxes, shipping charges, gift status and promotions for the order items in the order.

```
use Zerotoprod\Spapi\Spapi;

$Order = Spapi::from($access_token)
    ->orders()
    ->getOrderItems('111-5803802-7417822', ['curl_options']);

// Access the order.
echo $Order['response']['payload']['OrderItems'][0]['SellerSKU'];

// Access errors.
echo $Order['response']['errors']['code'];
```

Examples
--------

[](#examples)

### Get an order with a Restricted Data Token

[](#get-an-order-with-a-restricted-data-token)

```
use Zerotoprod\SpapiLwa\SpapiLwa;
use Zerotoprod\Spapi\Spapi;
use \Zerotoprod\SpapiRdt\SpapiRdt;

$lwa = SpapiLwa::from('amzn1.application-oa2-client.xxx','amzn1.oa2-cs.v1.xxx')
    ->refreshToken('Atzr|xxx');

$rdt = SpapiRdt::from($lwa['response']['access_token'],'amzn1.sp.solution.xxx')
    ->orders()
    ->getOrder('123-1234567-1234567', ['buyerInfo', 'shippingAddress']);

$response = Spapi::from($rdt['response']['restrictedDataToken'])
    ->orders()
    ->getOrder('111-5803802-7417822');

$Order = $response['response']['payload'];
```

Testing
-------

[](#testing)

### Basic Testing

[](#basic-testing)

The package provides a robust testing framework using the `SpapiFake` class. This allows you to mock API responses without making actual HTTP requests.

```
use Zerotoprod\Spapi\Support\Testing\SpapiFake;
use Zerotoprod\SpapiOrders\Support\Testing\SpapiOrdersResponseFactory;

// Mock the Spapi response
SpapiFake::fake(
    SpapiOrdersResponseFactory::factory()
        ->set('response.payload', [
            'AmazonOrderId' => '123-1234567-1234567'
        ])
        ->make()
);

// Use the API as normal
$Spapi = Spapi::from('access_token');
$response = $Spapi->orders()->getOrder('123-1234567-1234567');
```

### Testing with Authentication Flow

[](#testing-with-authentication-flow)

For testing the complete authentication flow, you'll need to mock both LWA (Login with Amazon) and RDT (Restricted Data Token) responses:

```
use Zerotoprod\SpapiLwa\Support\Testing\SpapiLwaFake;
use Zerotoprod\SpapiLwa\Support\Testing\SpapiLwaResponseFactory;
use Zerotoprod\SpapiRdt\Support\Testing\SpapiRdtFake;
use Zerotoprod\SpapiRdt\Support\Testing\SpapiRdtResponseFactory;
use Zerotoprod\SpapiLwa\SpapiLwa;
use Zerotoprod\SpapiTokens\SpapiTokens;
use Zerotoprod\SpapiRdt\SpapiRdt;

// Mock LWA response
SpapiLwaFake::fake(
    SpapiLwaResponseFactory::factory()
        ->asRefreshTokenResponse()
        ->make()
);

// Mock RDT response
SpapiRdtFake::fake(
    SpapiRdtResponseFactory::factory()->make()
);

// Get access token (in production code)
$access_token = SpapiLwa::from('client_id', 'client_secret')
    ->refreshToken('refresh_token');

// Get RDT token (in production code)
$rdt = SpapiRdt::from(
    SpapiTokens::from(
        $access_token['response']['access_token'],
        'app'
    )
)->orders()->getOrder('order-id')['response']['restrictedDataToken'];

// Mock Spapi response
SpapiFake::fake(
    SpapiOrdersResponseFactory::factory()
        ->set('response.payload', ['order_data'])
        ->make()
);

// Make the API call (in production code)
$Spapi = Spapi::from($rdt);
$Order = $Spapi->orders()->getOrder('order-id');
```

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

[](#contributing)

Contributions, issues, and feature requests are welcome! Feel free to check the [issues](https://github.com/zero-to-prod/spapi/issues) page if you want to contribute.

1. Fork the repository.
2. Create a new branch (`git checkout -b feature-branch`).
3. Commit changes (`git commit -m 'Add some feature'`).
4. Push to the branch (`git push origin feature-branch`).
5. Create a new Pull Request.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance52

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

16

Last Release

471d ago

Major Versions

v0.4.2 → v2.0.02025-02-02

v2.2.0 → v3.0.02025-02-02

### Community

Maintainers

![](https://www.gravatar.com/avatar/502649f05d36c87d494988bd99193a4d908d345335d99c080928a726277371f5?d=identicon)[zero-to-prod](/maintainers/zero-to-prod)

---

Top Contributors

[![zero-to-prod](https://avatars.githubusercontent.com/u/61474950?v=4)](https://github.com/zero-to-prod "zero-to-prod (23 commits)")

---

Tags

zero-to-prodspapi

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zero-to-prod-spapi/health.svg)

```
[![Health](https://phpackages.com/badges/zero-to-prod-spapi/health.svg)](https://phpackages.com/packages/zero-to-prod-spapi)
```

###  Alternatives

[zero-to-prod/data-model

Transforms Data into Type-Safe DTOs.

14226.2k32](/packages/zero-to-prod-data-model)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
