Step 5: Make Your First Call to the SP-API Sandbox
Send test requests and receive responses in the SP-API sandbox environment.
In this step, you get your authorization credentials and make your first call to the Selling Partner API (SP-API) static sandbox environment by using cURL. Windows 10+, MacOS, and Linux typically include cURL by default.
The sandbox environment simplifies authorization — you get hands-on experience with API calls without the need to set up a full authorization server or obtain seller permissions.
Although this step lets you quickly start making API calls, it focuses on basic API interaction rather than the complete authorization process required for production applications. In later steps, we explain the full authorization workflow needed for real seller interactions.
This tutorial uses the static sandbox, which uses pattern matching to return static, mocked responses. For detailed sandbox examples and tutorials, for both the static and dynamic sandbox, refer to Selling Partner API Sandbox.
Tips for success
- When you replace placeholder values in the examples, be careful not to accidentally overwrite apostrophes.
- Assemble cURL requests in text files first so that you can then copy and paste the full commands on the command line.
Prerequisites
Before you make API calls in the sandbox environment, follow the previous onboarding steps up to and including Step 4: Register a Sandbox Application.
Steps to get your credentials
In the following steps, you get your client ID, client secret, and refresh token from the Solution Provider Portal.
- Sign in to the Solution Provider Portal with your Amazon credentials.
- In the application list, find your application.
- In the row for your application, under LWA credentials, choose View sandbox credentials.
- Copy the Client identifier value, which is in the form
amzn1.application-oa2-client.XXXXXXXXX
. - Expand Client secret, and copy the value, which is in the form
amzn1.oa2-cs.v1.XXXXXXXXX
. - Choose Done.
- In the row for your application, under Action, choose the arrow, and then select Create Token.
- On the Sandbox Testing page, choose Create Token.
- Copy the sandbox refresh token value, which is in the form
Atzr|XXXXXXXXXX
.
Steps to call the SP-API in the sandbox
In the following steps, you call the getOrders
API within the static sandbox environment. Calls to the SP-API involve two steps: you must first call the authorization server to exchange a refresh token for an access token, and then you use the refresh token to call the SP-API.
-
In a text file, assemble the following access token request:
curl.exe --location --request POST 'https://api.amazon.com/auth/o2/token' --header 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8' --data-urlencode 'client_id=EXAMPLE_CLIENT_ID' --data-urlencode 'client_secret=EXAMPLE_CLIENT_SECRET' --data-urlencode 'grant_type=refresh_token' --data-urlencode 'refresh_token=EXAMPLE_REFRESH_TOKEN'
Replace
EXAMPLE_CLIENT_ID
,EXAMPLE_CLIENT_SECRET
, andEXAMPLE_REFRESH_TOKEN
with the values that you retrieved from the Solution Provider Portal in Steps to get your credentials.For compatibility with Windows, the example cURL command doesn't use slashes for line continuation, and explicitly specifies
curl.exe
. -
Open a command prompt, paste in the cURL request that you assembled in the previous step, and then press enter.
The response should return an access token in the formAtza|XXXXXXXXXX
{"access_token":"Atza|XXXXXXXX","token_type":"bearer","expires_in":3600}
-
Copy the access token from the response.
The access token is only valid for one hour. -
In a text file, assemble the request with the following parameters, which are from the
x-amzn-api-sandbox.static.request.parameters
object within thegetOrders
section of the Orders API v0 model.curl.exe --request GET --location 'EXAMPLE_ENDPOINT/orders/v0/orders?MarketplaceIds=ATVPDKIKX0DER&CreatedAfter=TEST_CASE_200' --header 'x-amz-access-token: EXAMPLE_ACCESS_TOKEN' --header 'Content-Type: application/json' --header 'User-Agent: My-Testing-App/1.0'
Replace the following values:
- Replace
EXAMPLE_ENDPOINT
to the sandbox endpoint for your region:- North America:
https://sandbox.sellingpartnerapi-na.amazon.com
- Europe:
https://sandbox.sellingpartnerapi-eu.amazon.com
- Far East:
https://sandbox.sellingpartnerapi-fe.amazon.com
- North America:
- Replace
EXAMPLE_ACCESS_TOKEN
with the access token that you retrieved at the beginning of this procedure.
- Replace
-
Paste in the cURL request that you assembled in the previous step, and then press enter.
The response should look something like the following example.{"payload":{"CreatedBefore":"1.569521782042E9","Orders":[{"AmazonOrderId":"902-1845936-5435065","PurchaseDate":"1970-01-19T03:58:30Z","LastUpdateDate":"1970-01-19T03:58:32Z","OrderStatus":"Unshipped","FulfillmentChannel":"MFN","SalesChannel":"Amazon.com","ShipServiceLevel":"Std US D2D Dom","OrderTotal":{"CurrencyCode":"USD","Amount":"11.01"},"NumberOfItemsShipped":0,"NumberOfItemsUnshipped":1,"PaymentMethod":"Other","PaymentMethodDetails":["Standard"],"IsReplacementOrder":false,"MarketplaceId":"ATVPDKIKX0DER","ShipmentServiceLevelCategory":"Standard","OrderType":"StandardOrder","EarliestShipDate":"1970-01-19T03:59:27Z","LatestShipDate":"1970-01-19T04:05:13Z","EarliestDeliveryDate":"1970-01-19T04:06:39Z","LatestDeliveryDate":"1970-01-19T04:15:17Z","IsBusinessOrder":false,"IsPrime":false,"IsGlobalExpressEnabled":false,"IsPremiumOrder":false,"IsSoldByAB":false,"IsIBA":false,"DefaultShipFromLocationAddress":{"Name":"MFNIntegrationTestMerchant","AddressLine1":"2201 WESTLAKE AVE","City":"SEATTLE","StateOrRegion":"WA","PostalCode":"98121-2778","CountryCode":"US","Phone":"+1 480-386-0930 ext. 73824","AddressType":"Commercial"},"FulfillmentInstruction":{"FulfillmentSupplySourceId":"sampleSupplySourceId"},"IsISPU":false,"IsAccessPointOrder":false,"AutomatedShippingSettings":{"HasAutomatedShippingSettings":false},"EasyShipShipmentStatus":"PendingPickUp","ElectronicInvoiceStatus":"NotRequired"},{"AmazonOrderId":"902-8745147-1934268","PurchaseDate":"1970-01-19T03:58:30Z","LastUpdateDate":"1970-01-19T03:58:32Z","OrderStatus":"Unshipped","FulfillmentChannel":"MFN","SalesChannel":"Amazon.com","ShipServiceLevel":"Std US D2D Dom","OrderTotal":{"CurrencyCode":"USD","Amount":"11.01"},"NumberOfItemsShipped":0,"NumberOfItemsUnshipped":1,"PaymentMethod":"Other","PaymentMethodDetails":["Standard"],"IsReplacementOrder":false,"MarketplaceId":"ATVPDKIKX0DER","ShipmentServiceLevelCategory":"Standard","OrderType":"StandardOrder","EarliestShipDate":"1970-01-19T03:59:27Z","LatestShipDate":"1970-01-19T04:05:13Z","EarliestDeliveryDate":"1970-01-19T04:06:39Z","LatestDeliveryDate":"1970-01-19T04:15:17Z","IsBusinessOrder":false,"IsPrime":false,"IsAccessPointOrder":false,"IsGlobalExpressEnabled":false,"IsPremiumOrder":false,"IsSoldByAB":false,"IsIBA":false,"EasyShipShipmentStatus":"PendingPickUp","ElectronicInvoiceStatus":"NotRequired"}]}}
-
Try other SP-API operations as follows:
- Find the model file for an API in the SP-API documentation.
For example, the Product Pricing API model is in Product Pricing API v2022-05-01 Model. - Within the model file, find an operation that you want to try.
- Within that operation's section, find the parameters within the
x-amzn-api-sandbox.static.request.parameters
object. - Assemble a cURL request in the following format:
curl.exe --location --request GET 'EXAMPLE_ENDPOINT/EXAMPLE_PATH?queryParam1=value1&queryParam2=value2' --header 'x-amz-access-token: EXAMPLE_ACCESS_TOKEN' --header 'Content-Type: application/json' --header 'User-Agent: My-Testing-App/1.0'
curl.exe --location --request POST 'EXAMPLE_ENDPOINT/EXAMPLE_PATH' --header 'x-amz-access-token: EXAMPLE_ACCESS_TOKEN' --header 'Content-Type: application/json' --header 'User-Agent: My-Testing-App/1.0' --data-raw '{ "key1": "value1", "key2": "value2"}
- Find the model file for an API in the SP-API documentation.
Next steps
Proceed to Step 6: Set up the Authorization Workflow.
Updated 12 days ago