zero-to-prod / spapi-orders-cli
A CLI for Amazon Selling Partner API (SPAPI) Orders API.
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: ^4.0
- zero-to-prod/spapi-orders: ^3.0
- zero-to-prod/spapi-rdt: ^4.0
- zero-to-prod/spapi-tokens: ^3.1.2
Requires (Dev)
- phpunit/phpunit: <12.0
README
Contents
- Introduction
- Requirements
- Installation
- Documentation Publishing
- Usage
- Docker Image
- Local Development
- Image Development
- Contributing
Introduction
A CLI for Amazon Selling Partner API (SPAPI) Orders API.
Requirements
- PHP 8.1 or higher.
Installation
Install Zerotoprod\SpapiOrdersCli
via Composer:
composer require zero-to-prod/spapi-orders-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-orders-cli) vendor/bin/zero-to-prod-spapi-orders-cli # Publish to custom directory vendor/bin/zero-to-prod-spapi-orders-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-orders-cli" ], "post-update-cmd": [ "zero-to-prod-spapi-orders-cli" ] } }
Usage
Run this command to see the available commands:
vendor/bin/spapi-orders-cli list
Available Commands
spapi-orders-cli:src
Displays the project's GitHub repository URL.
Usage:
vendor/bin/spapi-orders-cli spapi-orders-cli:src
Arguments: None
Example:
vendor/bin/spapi-orders-cli spapi-orders-cli:src
Sample Output:
https://github.com/zero-to-prod/spapi-orders-cli
spapi-orders-cli:get-order
Retrieves order details from Amazon's Selling Partner API for a specific order ID.
Usage:
vendor/bin/spapi-orders-cli spapi-orders-cli:get-order <refresh_token> <client_id> <client_secret> <target_application> <order_id> [options]
Required Arguments:
refresh_token
- The LWA refresh tokenclient_id
- Get this value when you register your applicationclient_secret
- Get this value when you register your applicationtarget_application
- The application ID for the target application to which access is being delegatedorder_id
- The Amazon Order ID
Options:
--user_agent
- User Agent (optional)--response
- Returns the full response (flag)--expiresIn
- The expiresIn value for the restrictedDataToken (flag)
Example:
vendor/bin/spapi-orders-cli spapi-orders-cli:get-order "refresh_token_here" "client_id_here" "client_secret_here" "app_id_here" "123-4567890-1234567"
Sample Output:
{ "AmazonOrderId": "123-4567890-1234567", "PurchaseDate": "2023-12-01T14:30:00Z", "LastUpdateDate": "2023-12-02T10:15:00Z", "OrderStatus": "Shipped", "FulfillmentChannel": "MFN", "SalesChannel": "Amazon.com", "OrderChannel": "Online", "ShipServiceLevel": "Std US D2D Dom", "NumberOfItemsShipped": 1, "NumberOfItemsUnshipped": 0, "PaymentExecutionDetail": [], "PaymentMethod": "Other", "MarketplaceId": "ATVPDKIKX0DER", "BuyerEmail": "buyer@example.com", "BuyerName": "John Doe", "BuyerCounty": "King", "BuyerTaxInfo": { "CompanyLegalName": "Example Company", "TaxingRegion": "WA", "TaxClassifications": [] }, "ShipmentServiceLevelCategory": "Standard", "ShippedByAmazonTFM": false, "TFMShipmentStatus": "PendingPickUp", "OrderType": "StandardOrder", "EarliestShipDate": "2023-12-01T00:00:00Z", "LatestShipDate": "2023-12-03T23:59:59Z", "EarliestDeliveryDate": "2023-12-05T00:00:00Z", "LatestDeliveryDate": "2023-12-08T23:59:59Z", "IsBusinessOrder": false, "IsPrime": true, "IsPremiumOrder": false, "IsGlobalExpressEnabled": false, "ReplacedOrderId": null, "IsReplacementOrder": false, "PromiseResponseDueDate": "2023-12-01T16:30:00Z", "IsEstimatedShipDateSet": false }
spapi-orders-cli:get-order-items
Retrieves the items for a specific order from Amazon's Selling Partner API.
Usage:
vendor/bin/spapi-orders-cli spapi-orders-cli:get-order-items <refresh_token> <client_id> <client_secret> <target_application> <order_id> [options]
Required Arguments:
refresh_token
- The LWA refresh tokenclient_id
- Get this value when you register your applicationclient_secret
- Get this value when you register your applicationtarget_application
- The application ID for the target application to which access is being delegatedorder_id
- The Amazon Order ID
Options:
--user_agent
- User Agent (optional)--response
- Returns the full response (flag)--expiresIn
- The expiresIn value for the restrictedDataToken (flag)
Example:
vendor/bin/spapi-orders-cli spapi-orders-cli:get-order-items "refresh_token_here" "client_id_here" "client_secret_here" "app_id_here" "123-4567890-1234567"
Sample Output:
{ "OrderItems": [ { "ASIN": "B08N5WRWNW", "SellerSKU": "SKU-12345", "OrderItemId": "12345678901234", "Title": "Example Product Title", "QuantityOrdered": 1, "QuantityShipped": 1, "ProductInfo": { "NumberOfItems": 1 }, "PointsGranted": { "PointsNumber": 0 }, "ItemPrice": { "CurrencyCode": "USD", "Amount": "29.99" }, "ShippingPrice": { "CurrencyCode": "USD", "Amount": "5.99" }, "ItemTax": { "CurrencyCode": "USD", "Amount": "2.70" }, "ShippingTax": { "CurrencyCode": "USD", "Amount": "0.54" }, "ShippingDiscount": { "CurrencyCode": "USD", "Amount": "0.00" }, "PromotionDiscount": { "CurrencyCode": "USD", "Amount": "0.00" }, "ConditionId": "New", "ConditionSubtypeId": "New", "ConditionNote": "", "PriceDesignation": "BusinessPrice", "TaxCollection": { "Model": "MarketplaceFacilitator", "ResponsibleParty": "Amazon Services, Inc." }, "SerialNumberRequired": false, "IsTransparency": false, "IossNumber": "", "StoreChainStoreId": "", "DeemedResellerCategory": "IOSS", "BuyerInfo": { "BuyerCustomizedInfo": { "CustomizedURL": "" }, "GiftWrapPrice": { "CurrencyCode": "USD", "Amount": "0.00" }, "GiftWrapTax": { "CurrencyCode": "USD", "Amount": "0.00" }, "GiftMessageText": "", "GiftWrapLevel": "None" } } ] }
spapi-orders-cli:get-order-buyer-info
Retrieves buyer information for a specific order from Amazon's Selling Partner API.
Usage:
vendor/bin/spapi-orders-cli spapi-orders-cli:get-order-buyer-info <refresh_token> <client_id> <client_secret> <target_application> <order_id> [options]
Required Arguments:
refresh_token
- The LWA refresh tokenclient_id
- Get this value when you register your applicationclient_secret
- Get this value when you register your applicationtarget_application
- The application ID for the target application to which access is being delegatedorder_id
- The Amazon Order ID
Options:
--user_agent
- User Agent (optional)--response
- Returns the full response (flag)--expiresIn
- The expiresIn value for the restrictedDataToken (flag)
Example:
vendor/bin/spapi-orders-cli spapi-orders-cli:get-order-buyer-info "refresh_token_here" "client_id_here" "client_secret_here" "app_id_here" "123-4567890-1234567"
Sample Output:
{ "AmazonOrderId": "123-4567890-1234567", "BuyerEmail": "buyer@example.com", "BuyerName": "John Doe", "BuyerCounty": "King", "BuyerTaxInfo": { "CompanyLegalName": "Example Company Inc.", "TaxingRegion": "WA", "TaxClassifications": [ { "Name": "VAT", "Value": "US123456789" } ] }, "PurchaseOrderNumber": "PO-2023-12345" }
spapi-orders-cli:get-order-address
Returns the shipping address for the specified order from Amazon's Selling Partner API.
Usage:
vendor/bin/spapi-orders-cli spapi-orders-cli:get-order-address <refresh_token> <client_id> <client_secret> <target_application> <order_id> [options]
Required Arguments:
refresh_token
- The LWA refresh tokenclient_id
- Get this value when you register your applicationclient_secret
- Get this value when you register your applicationtarget_application
- The application ID for the target application to which access is being delegatedorder_id
- The Amazon Order ID
Options:
--user_agent
- User Agent (optional)--response
- Returns the full response (flag)--expiresIn
- The expiresIn value for the restrictedDataToken (flag)
Example:
vendor/bin/spapi-orders-cli spapi-orders-cli:get-order-address "refresh_token_here" "client_id_here" "client_secret_here" "app_id_here" "123-4567890-1234567"
Sample Output:
{ "AmazonOrderId": "123-4567890-1234567", "ShippingAddress": { "Name": "John Doe", "AddressLine1": "123 Main Street", "AddressLine2": "Apt 456", "AddressLine3": "", "City": "Seattle", "County": "King", "District": "", "StateOrRegion": "WA", "Municipality": "", "PostalCode": "98101", "CountryCode": "US", "Phone": "555-123-4567", "AddressType": "Residential" } }
Note: All SPAPI commands return JSON-formatted responses. Make sure to have valid Amazon SP-API credentials and proper permissions to access order data.
Docker Image
You can also run the cli using the docker image:
docker run --rm davidsmith3/spapi-orders-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.