Amazon Product Advertising API: How to translate Curl statement into Python?
I got a signed curl request from this Amazon link. The curl statement looks like this, sensitive info redacted:
curl "https://webservices.amazon.com/paapi5/searchitems" \
-H "Host: webservices.amazon.com" \
-H "Content-Type: application/json; charset=UTF-8" \
-H "X-Amz-Date: 20230301T020028Z" \
-H "X-Amz-Target: com.amazon.paapi5.v1.ProductAdvertisingAPIv1.SearchItems" \
-H "Content-Encoding: amz-1.0" \
-H "User-Agent: paapi-docs-curl/1.0.0" \
-H "Authorization: SENSITIVE_INFO_REDACTED" \
-d "{\"Marketplace\":\"www.amazon.com\",\"PartnerType\":\"Associates\",\"PartnerTag\":\"STORE_NAME",\"Keywords\":\"kindle\",\"SearchIndex\":\"All\",\"ItemCount\":3,\"Resources\":[\"Images.Primary.Large\",\"ItemInfo.Title\",\"Offers.Listings.Price\"]}"
I translated the above into Python. This is my Python code below. However, I'm getting a Response 401 error
:
headers = {
'Host': 'webservices.amazon.com',
'Content-Type': 'application/json; charset=UTF-8',
'X-Amz-Date': '20230301T020028Z',
'X-Amz-Target': 'com.amazon.paapi5.v1.ProductAdvertisingAPIv1.SearchItems',
'Content-Encoding': 'amz-1.0',
'User-Agent': 'paapi-docs-curl/1.0.0',
'Authorization': 'SENSITIVE_INFO_REDACTED',
}
json_data = {
'Marketplace': 'www.amazon.com',
'PartnerType': 'Associates',
'PartnerTag': 'STORE_NAME',
'Keywords': 'kindle',
'SearchIndex': 'All',
'ItemCount': 3,
'Resources': [
'Images.Primary.Large',
'ItemInfo.Title',
'Offers.Listings.Price',
],
}
response = requests.post('https://webservices.amazon.com/paapi5/searchitems', headers=headers, json=json_data)