zero-to-prod / spapi-lwa-cli
A CLI for connecting to Amazons Selling Partner API with Login With Amazon (LWA).
Fund package maintenance!
Github
Requires
- php: >=8.1
- ext-curl: *
- ext-json: *
- symfony/console: ^7.2
- zero-to-prod/data-model: ^81.9
- zero-to-prod/package-helper: ^1.1.3
- zero-to-prod/spapi-lwa: ^2.0
Requires (Dev)
- phpunit/phpunit: <12.0
This package is auto-updated.
Last update: 2025-09-02 02:01:33 UTC
README
Contents
- Introduction
- Requirements
- Installation
- Documentation Publishing
- Usage
- Docker Image
- Local Development
- Image Development
- Contributing
Introduction
A CLI for connecting to Amazons Selling Partner API with Login With Amazon (LWA).
Requirements
- PHP 8.1 or higher.
Installation
Install Zerotoprod\SpapiLwaCli
via Composer:
composer require zero-to-prod/spapi-lwa-cli
This will add the package to your project's dependencies and create an autoloader entry for it.
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-lwa-cli) vendor/bin/zero-to-prod-spapi-lwa-cli # Publish to custom directory vendor/bin/zero-to-prod-spapi-lwa-cli /path/to/your/docs
Automatic Documentation Publishing
You can automatically publish documentation by adding the following to your composer.json
:
{ "scripts": { "post-install-cmd": [ "zero-to-prod-spapi-lwa-cli" ], "post-update-cmd": [ "zero-to-prod-spapi-lwa-cli" ] } }
Usage
Run this command to see the available commands:
vendor/bin/spapi-lwa-cli list
Available Commands
spapi-lwa-cli:refresh-token
Description: Login With Amazon with a refresh_token.
Usage:
vendor/bin/spapi-lwa-cli spapi-lwa-cli:refresh-token [options] <refresh_token> <client_id> <client_secret>
Arguments:
refresh_token
(required): The LWA refresh tokenclient_id
(required): Get this value when you register your applicationclient_secret
(required): Get this value when you register your application
Options:
--user_agent[=USER_AGENT]
: User Agent--response
: Returns the full response--refresh_token
: Returns the refresh_token--token_type
: Returns the token_type--expires_in
: Returns expires_in
Examples:
# Get access token (default behavior) vendor/bin/spapi-lwa-cli spapi-lwa-cli:refresh-token "your-refresh-token" "your-client-id" "your-client-secret" # Get the full response vendor/bin/spapi-lwa-cli spapi-lwa-cli:refresh-token "your-refresh-token" "your-client-id" "your-client-secret" --response # Get only the token type vendor/bin/spapi-lwa-cli spapi-lwa-cli:refresh-token "your-refresh-token" "your-client-id" "your-client-secret" --token_type # With custom user agent vendor/bin/spapi-lwa-cli spapi-lwa-cli:refresh-token "your-refresh-token" "your-client-id" "your-client-secret" --user_agent="MyApp/1.0"
Sample Output (access token):
Atzr|IwEBIAxHQiJEuOjl-123456789abcdef...
Sample Output (full response with --response
):
{ "response": { "access_token": "Atzr|IwEBIAxHQiJEuOjl-123456789abcdef...", "token_type": "bearer", "expires_in": 3600, "refresh_token": "Atzr|IwEBIA..." }, "info": { "url": "https://api.amazon.com/auth/o2/token", "content_type": "application/json; charset=utf-8", "http_code": 200, "total_time": 0.234567 } }
spapi-lwa-cli:client-credentials
Description: Login With Amazon with client credentials.
Usage:
vendor/bin/spapi-lwa-cli spapi-lwa-cli:client-credentials [options] <scope> <client_id> <client_secret>
Arguments:
scope
(required): The scope of the LWA authorization grantclient_id
(required): Get this value when you register your applicationclient_secret
(required): Get this value when you register your application
Options:
--user_agent[=USER_AGENT]
: User Agent--response
: Returns the full response--scope
: Returns the scope--token_type
: Returns the token_type--expires_in
: Returns expires_in
Examples:
# Get access token (default behavior) vendor/bin/spapi-lwa-cli spapi-lwa-cli:client-credentials "sellingpartnerapi::notifications" "your-client-id" "your-client-secret" # Get the full response vendor/bin/spapi-lwa-cli spapi-lwa-cli:client-credentials "sellingpartnerapi::notifications" "your-client-id" "your-client-secret" --response # Get only the scope vendor/bin/spapi-lwa-cli spapi-lwa-cli:client-credentials "sellingpartnerapi::notifications" "your-client-id" "your-client-secret" --scope # With custom user agent vendor/bin/spapi-lwa-cli spapi-lwa-cli:client-credentials "sellingpartnerapi::notifications" "your-client-id" "your-client-secret" --user_agent="MyApp/1.0"
Sample Output (access token):
Atza|IwEBIAxHQiJEuOjl-987654321fedcba...
Sample Output (full response with --response
):
{ "response": { "access_token": "Atza|IwEBIAxHQiJEuOjl-987654321fedcba...", "scope": "sellingpartnerapi::notifications", "token_type": "bearer", "expires_in": 3600 }, "info": { "url": "https://api.amazon.com/auth/o2/token", "content_type": "application/json; charset=utf-8", "http_code": 200, "total_time": 0.567890 } }
spapi-lwa-cli:src
Description: Project source link
Usage:
vendor/bin/spapi-lwa-cli spapi-lwa-cli:src
Arguments: None
Options: None
Example:
vendor/bin/spapi-lwa-cli spapi-lwa-cli:src
Sample Output:
https://github.com/zero-to-prod/spapi-lwa-cli
Docker Image
You can also run the cli using the docker image:
docker run --rm davidsmith3/spapi-lwa-cli
Contributing
Contributions, issues, and feature requests are welcome! Feel free to check the issues page if you want to contribute.
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Commit changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature-branch
). - Create a new Pull Request.