1

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)
Katsu
  • 8,479
  • 3
  • 15
  • 16
  • Hmm, 401 error indicates lack of authorization. Does the original bash curl request work for you? Are you sure you have the Authorization correct? Also, make sure the X-Amz-Date is updated? – Plonetheus Mar 01 '23 at 19:50

0 Answers0