PHPackages                             zero-to-prod/spapi-tokens-cli - 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. [CLI &amp; Console](/categories/cli)
4. /
5. zero-to-prod/spapi-tokens-cli

ActiveLibrary[CLI &amp; Console](/categories/cli)

zero-to-prod/spapi-tokens-cli
=============================

A CLI for getting a Restricted Data Token (RDT) for Amazon Selling Partner API (SPAPI).

v2.1.0(1y ago)12251MITPHPPHP &gt;=8.1CI passing

Since Feb 2Pushed 10mo ago1 watchersCompare

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

READMEChangelog (7)Dependencies (6)Versions (8)Used By (1)

Zerotoprod\\SpapiTokensCli
==========================

[](#zerotoprodspapitokenscli)

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

[![Repo](https://camo.githubusercontent.com/9a90a3efeee26aed7d7f2feee9cd84566a26f9c362cc773b184d076210906e1c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6769746875622d677261793f6c6f676f3d676974687562)](https://github.com/zero-to-prod/spapi-tokens-cli)[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/869f2478edddbd116da7a59ec17c0d3bb3d6763a5f3501c26dd40b62a09e041c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7a65726f2d746f2d70726f642f73706170692d746f6b656e732d636c692f746573742e796d6c3f6c6162656c3d74657374)](https://github.com/zero-to-prod/spapi-tokens-cli/actions)[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/ac1cf2cae4da4258d8d352bc35a6d9f049b086437473677ae2016e4187cb8910/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7a65726f2d746f2d70726f642f73706170692d746f6b656e732d636c692f6261636b77617264735f636f6d7061746962696c6974792e796d6c3f6c6162656c3d6261636b77617264735f636f6d7061746962696c697479)](https://github.com/zero-to-prod/spapi-tokens-cli/actions)[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/7953c19c0d4d3c451c832233c31b52fa8ecad00eea72a0784900d47dd763ddd5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7a65726f2d746f2d70726f642f73706170692d746f6b656e732d636c692f6275696c645f646f636b65725f696d6167652e796d6c3f6c6162656c3d6275696c645f646f636b65725f696d616765)](https://github.com/zero-to-prod/spapi-tokens-cli/actions)[![Packagist Downloads](https://camo.githubusercontent.com/cd7ca6ba72190c738fc3df098eb7908ae349df5d1de2e663c5626b3ee7ae8335/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a65726f2d746f2d70726f642f73706170692d746f6b656e732d636c693f636f6c6f723d626c7565)](https://packagist.org/packages/zero-to-prod/spapi-tokens-cli/stats)[![php](https://camo.githubusercontent.com/32fe4568c07fb4b4b08d667744bccf2c91745ea7977187a2afc5d154e6d63da7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7a65726f2d746f2d70726f642f73706170692d746f6b656e732d636c692e7376673f636f6c6f723d707572706c65)](https://packagist.org/packages/zero-to-prod/spapi-tokens-cli/stats)[![Packagist Version](https://camo.githubusercontent.com/f7fe84aa31865436977259af36edba0e08cfc5fb06f03ead1da544a7c5581141/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a65726f2d746f2d70726f642f73706170692d746f6b656e732d636c693f636f6c6f723d663238643161)](https://packagist.org/packages/zero-to-prod/spapi-tokens-cli)[![License](https://camo.githubusercontent.com/37c5e5c87b59953be5f92d610da1717c7aa945924a29ea88882c3bdde109a84e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7a65726f2d746f2d70726f642f73706170692d746f6b656e732d636c693f636f6c6f723d70696e6b)](https://github.com/zero-to-prod/spapi-tokens-cli/blob/main/LICENSE.md)[![wakatime](https://camo.githubusercontent.com/c253dd89b5ede4e2e0bad1b06935886eb6c80a232016b9f5fd0d86abdc9423ce/68747470733a2f2f77616b6174696d652e636f6d2f62616467652f6769746875622f7a65726f2d746f2d70726f642f73706170692d746f6b656e732d636c692e737667)](https://wakatime.com/badge/github/zero-to-prod/spapi-tokens-cli)[![Hits-of-Code](https://camo.githubusercontent.com/51e5455f0c6065f0bb6ffc3c84304ec5c984bc8ff986fed94b89e3bd993e3db9/68747470733a2f2f686974736f66636f64652e636f6d2f6769746875622f7a65726f2d746f2d70726f642f73706170692d746f6b656e732d636c693f6272616e63683d6d61696e)](https://hitsofcode.com/github/zero-to-prod/spapi-tokens-cli/view?branch=main)

Contents
--------

[](#contents)

- [Introduction](#introduction)
- [Requirements](#requirements)
- [Installation](#installation)
- [Documentation Publishing](#documentation-publishing)
    - [Automatic Documentation Publishing](#automatic-documentation-publishing)
- [Usage](#usage)
    - [Available Commands](#available-commands)
        - [`spapi-tokens-cli:src`](#spapi-tokens-clisrc)
        - [`spapi-tokens-cli:rdt`](#spapi-tokens-clirdt)
        - [`spapi-tokens-cli:rdt-from-token`](#spapi-tokens-clirdt-from-token)
        - [`spapi-tokens-cli:rdt-from-scope`](#spapi-tokens-clirdt-from-scope)
- [Docker Image](#docker-image)
- [Local Development](./LOCAL_DEVELOPMENT.md)
- [Image Development](./IMAGE_DEVELOPMENT.md)
- [Contributing](#contributing)

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

[](#introduction)

A CLI for getting a Restricted Data Token (RDT) for Amazon Selling Partner API (SPAPI).

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

[](#requirements)

- PHP 8.1 or higher.

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

[](#installation)

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

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

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-tokens-cli)
vendor/bin/zero-to-prod-spapi-tokens-cli

# Publish to custom directory
vendor/bin/zero-to-prod-spapi-tokens-cli /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-tokens-cli"
        ],
        "post-update-cmd": [
            "zero-to-prod-spapi-tokens-cli"
        ]
    }
}
```

Usage
-----

[](#usage)

Run this command to see the available commands:

```
vendor/bin/spapi-tokens-cli list
```

### Available Commands

[](#available-commands)

#### `spapi-tokens-cli:src`

[](#spapi-tokens-clisrc)

Displays the project's GitHub repository URL.

**Usage:**

```
vendor/bin/spapi-tokens-cli spapi-tokens-cli:src
```

**Arguments:** None

**Example:**

```
vendor/bin/spapi-tokens-cli spapi-tokens-cli:src
```

**Output:**

```
https://github.com/zero-to-prod/spapi-tokens-cli

```

#### `spapi-tokens-cli:rdt`

[](#spapi-tokens-clirdt)

Get a Restricted Data Token (RDT) for restricted resources using an existing access token.

**Usage:**

```
vendor/bin/spapi-tokens-cli spapi-tokens-cli:rdt     [options]
```

**Arguments:**

- `access_token` (required): The access token to get a restricted resource
- `path` (required): The path in the restricted resource
- `dataElements` (required): Comma separated list of data elements. Indicates the type of Personally Identifiable Information requested
- `targetApplication` (required): The application ID for the target application to which access is being delegated

**Options:**

- `--user_agent`: User Agent (optional)
- `--response`: Returns the full response
- `--expiresIn`: The expiresIn value for the restrictedDataToken

**Example:**

```
vendor/bin/spapi-tokens-cli spapi-tokens-cli:rdt \
  "Atza|IwEBIExampleAccessToken" \
  "/orders/v0/orders/123-4567890-1234567/buyerInfo" \
  "buyerInfo" \
  "amzn1.sp.solution.12345678-1234-1234-1234-123456789012"
```

**Example Response (default - token only):**

```
Atzr|IwEBIB6MHXJl5sLqTf_3n2e7TJQ4a3X7hZ2Y9k8N3F1R6Q5E4P2A9S8D7G6H5J4K3L2M1

```

**Example Response (with --response flag):**

```
{
    "response": {
        "restrictedDataToken": "Atzr|IwEBIB6MHXJl5sLqTf_3n2e7TJQ4a3X7hZ2Y9k8N3F1R6Q5E4P2A9S8D7G6H5J4K3L2M1",
        "expiresIn": 3600
    },
    "info": {
        "http_code": 200
    }
}
```

**Example Response (with --expiresIn flag):**

```
3600

```

#### `spapi-tokens-cli:rdt-from-token`

[](#spapi-tokens-clirdt-from-token)

Get a Restricted Data Token (RDT) for restricted resources from a refresh token. This command first exchanges the refresh token for an access token, then uses that access token to obtain the RDT.

**Usage:**

```
vendor/bin/spapi-tokens-cli spapi-tokens-cli:rdt-from-token       [options]
```

**Arguments:**

- `refresh_token` (required): The LWA refresh token
- `client_id` (required): Get this value when you register your application
- `client_secret` (required): Get this value when you register your application
- `path` (required): The path in the restricted resource
- `dataElements` (required): Comma separated list of data elements. Indicates the type of Personally Identifiable Information requested
- `targetApplication` (required): The application ID for the target application to which access is being delegated

**Options:**

- `--user_agent`: User Agent (optional)
- `--response`: Returns the full response
- `--expiresIn`: The expiresIn value for the restrictedDataToken

**Example:**

```
vendor/bin/spapi-tokens-cli spapi-tokens-cli:rdt-from-token \
  "Atzr|IwEBIExampleRefreshToken" \
  "amzn1.application-oa2-client.12345678901234567890123456789012" \
  "your-client-secret-here" \
  "/orders/v0/orders/123-4567890-1234567/buyerInfo" \
  "buyerInfo" \
  "amzn1.sp.solution.12345678-1234-1234-1234-123456789012"
```

**Example Response (default - token only):**

```
Atzr|IwEBIB6MHXJl5sLqTf_3n2e7TJQ4a3X7hZ2Y9k8N3F1R6Q5E4P2A9S8D7G6H5J4K3L2M1

```

**Example Response (with --response flag):**

```
{
    "response": {
        "restrictedDataToken": "Atzr|IwEBIB6MHXJl5sLqTf_3n2e7TJQ4a3X7hZ2Y9k8N3F1R6Q5E4P2A9S8D7G6H5J4K3L2M1",
        "expiresIn": 3600
    },
    "info": {
        "http_code": 200
    }
}
```

**Example Response (with --expiresIn flag):**

```
3600

```

**Example Error Response (invalid credentials):**

```
{
    "response": {
        "error": "invalid_client",
        "error_description": "Client authentication failed"
    },
    "info": {
        "http_code": 401
    }
}
```

#### `spapi-tokens-cli:rdt-from-scope`

[](#spapi-tokens-clirdt-from-scope)

Get a Restricted Data Token (RDT) for restricted resources from a scope using client credentials. This command uses client credentials flow to obtain an access token, then uses that access token to obtain the RDT.

**Usage:**

```
vendor/bin/spapi-tokens-cli spapi-tokens-cli:rdt-from-scope       [options]
```

**Arguments:**

- `scope` (required): The LWA scope for the client credentials flow
- `client_id` (required): Get this value when you register your application
- `client_secret` (required): Get this value when you register your application
- `path` (required): The path in the restricted resource
- `dataElements` (required): Comma separated list of data elements. Indicates the type of Personally Identifiable Information requested
- `targetApplication` (required): The application ID for the target application to which access is being delegated

**Options:**

- `--user_agent`: User Agent (optional)
- `--response`: Returns the full response
- `--expiresIn`: The expiresIn value for the restrictedDataToken

**Example:**

```
vendor/bin/spapi-tokens-cli spapi-tokens-cli:rdt-from-scope \
  "sellingpartnerapi::notifications" \
  "amzn1.application-oa2-client.12345678901234567890123456789012" \
  "your-client-secret-here" \
  "/orders/v0/orders/123-4567890-1234567/buyerInfo" \
  "buyerInfo" \
  "amzn1.sp.solution.12345678-1234-1234-1234-123456789012"
```

**Example Response (default - token only):**

```
Atzr|IwEBIB6MHXJl5sLqTf_3n2e7TJQ4a3X7hZ2Y9k8N3F1R6Q5E4P2A9S8D7G6H5J4K3L2M1

```

**Example Response (with --response flag):**

```
{
    "response": {
        "restrictedDataToken": "Atzr|IwEBIB6MHXJl5sLqTf_3n2e7TJQ4a3X7hZ2Y9k8N3F1R6Q5E4P2A9S8D7G6H5J4K3L2M1",
        "expiresIn": 3600
    },
    "info": {
        "http_code": 200
    }
}
```

**Example Response (with --expiresIn flag):**

```
3600

```

**Example Error Response (invalid scope):**

```
{
    "response": {
        "error": "invalid_scope",
        "error_description": "The scope sellingpartnerapi::notifications is not valid for this application"
    },
    "info": {
        "http_code": 400
    }
}
```

Docker Image
------------

[](#docker-image)

You can also run the cli using the [docker image](https://hub.docker.com/repository/docker/davidsmith3/spapi-tokens-cli/general):

```
docker run --rm davidsmith3/spapi-tokens-cli
```

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

[](#contributing)

Contributions, issues, and feature requests are welcome! Feel free to check the [issues](https://github.com/zero-to-prod/spapi-tokens-cli/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

33

—

LowBetter than 72% of packages

Maintenance48

Moderate activity, may be stable

Popularity14

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.8% 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

7

Last Release

518d ago

Major Versions

v1.0.2 → v2.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 (15 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

zero-to-prodspapi-tokens-cli

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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