Authorization Workflow
This document explains the Website Authorization Workflow for connecting seller accounts to your application using Amazon's SP-API. It is a simplified and easy-to-follow guide, presented in clear, step-by-step instructions.
What is Website Authorization Workflow?
Prerequisites
Amazon Developer Account
Amazon Developer Central
.App Registration
Client ID
, Client Secret
, and App ID
OAuth Redirect URI
Application Scope
sellingpartnerapi::migration
or sellingpartnerapi::notifications
Step-by-Step Guide
Step 1: Build the Authorization URL
application_id
: Your application's ID (e.g., amzn1.sellerapps.app.123456)state
: A unique, random string to protect against CSRF attacks (e.g., secure_random_string)redirect_uri
: Your app's callback URI (e.g., https://yourapp.com/oauth/callback)https://sellercentral.amazon.com/apps/authorize/consent
?application_id=amzn1.sellerapps.app.123456
&state=secure_random_string
&redirect_uri=https://zamorins-sp-api.com/oauth/callback
Step 2: Seller Logs In and Grants Permissions
1.
2.
redirect_uri
with the following query parameters:state
: The same state string you sent (validate this)code
: The authorization code you'll use to get tokens
Step 3: Exchange Authorization Code for Tokens
POST
request to Amazon's OAuth token endpoint to exchange the code for an access token
and refresh token
.https://api.amazon.com/auth/o2/token
{
"grant_type": "authorization_code",
"code": "<AUTHORIZATION_CODE>",
"redirect_uri": "<YOUR_REDIRECT_URI>",
"client_id": "<CLIENT_ID>",
"client_secret": "<CLIENT_SECRET>"
}
{
"access_token": "Atza|IwEBL0B1...",
"refresh_token": "Atzr|IwEBL0B1...",
"token_type": "bearer",
"expires_in": 3600
}
Step 4: Use Access Token for API Requests
access_token
to make API requests to SP-API endpoints on behalf of the seller. Include the token in the Authorization header:
Step 5: Refresh Tokens When Expired
refresh_token
to request a new access_token
.{
"grant_type": "refresh_token",
"refresh_token": "<REFRESH_TOKEN>",
"client_id": "<CLIENT_ID>",
"client_secret": "<CLIENT_SECRET>"
}
Best Practices
client_secret
and refresh_token
securely using tools like AWS Secrets Manager or encrypted databasesstate
parameter in the redirect matches your original stringCommon Errors
Error Code | Description | Solution |
---|---|---|
invalid_grant | Invalid or expired authorization code | Ensure the code is valid and hasn't expired |
unauthorized_client | Client ID/Secret is invalid | Verify your app credentials |
invalid_request | Incorrect request format | Check all required parameters |