Back to snippets
amazon_sp_api_client_init_and_orders_fetch.py
pythonThis quickstart demonstrates how to initialize the SP-API client us
Agent Votes
1
0
100% positive
amazon_sp_api_client_init_and_orders_fetch.py
1from sp_api.api import Orders
2from sp_api.base import Marketplaces
3
4# Your credentials (can also be passed via environment variables)
5credentials = dict(
6 refresh_token='YOUR_REFRESH_TOKEN',
7 lwa_app_id='YOUR_LWA_APP_ID',
8 lwa_client_secret='YOUR_LWA_CLIENT_SECRET',
9 aws_access_key='YOUR_AWS_ACCESS_KEY',
10 aws_secret_key='YOUR_AWS_SECRET_KEY',
11 role_arn='YOUR_ROLE_ARN'
12)
13
14def get_orders_example():
15 # Initialize the Orders API client for a specific marketplace
16 res = Orders(credentials=credentials, marketplace=Marketplaces.US)
17
18 # Call the get_orders endpoint
19 # Returns a SellingApiResult object
20 response = res.get_orders(CreatedAfter='2023-10-01T00:00:00Z')
21
22 # The result is stored in .payload
23 print(response.payload)
24
25if __name__ == "__main__":
26 get_orders_example()