I am trying to get product information through the Amazon Product Advertising API 5.0 but I keep getting the same error:
Error calling PA-API 5.0!
Status code: 429
Errors : {"__type":"com.amazon.paapi5#TooManyRequestsException","Errors":[{"Code":"TooManyRequests","Message":"The request was denied due to request throttling. Please verify the number of requests made per second to the Amazon Product Advertising API."}]}
Request ID: ee3f3ad0-e512-463f-b34b-395af81e347d
I followed the instructions in the docs, but I can't seem to solve the problem.
I downloaded the python example package and used the sample_get_items_api.py script:
from paapi5_python_sdk.api.default_api import DefaultApi
from paapi5_python_sdk.models.condition import Condition
from paapi5_python_sdk.models.get_items_request import GetItemsRequest
from paapi5_python_sdk.models.get_items_resource import GetItemsResource
from paapi5_python_sdk.models.partner_type import PartnerType
from paapi5_python_sdk.rest import ApiException
def parse_response(item_response_list):
"""
The function parses GetItemsResponse and creates a dict of ASIN to Item object
:param item_response_list: List of Items in GetItemsResponse
:return: Dict of ASIN to Item object
"""
mapped_response = {}
for item in item_response_list:
mapped_response[item.asin] = item
return mapped_response
def get_items():
""" Following are your credentials """
""" Please add your access key here """
access_key = "<YOUR ACCESS KEY>"
""" Please add your secret key here """
secret_key = "<YOUR SECRET KEY>"
""" Please add your partner tag (store/tracking id) here """
partner_tag = "<YOUR PARTNER TAG>"
""" PAAPI host and region to which you want to send request """
""" For more details refer: https://webservices.amazon.com/paapi5/documentation/common-request-parameters.html#host-and-region"""
host = "webservices.amazon.com"
region = "us-east-1"
""" API declaration """
default_api = DefaultApi(
access_key=access_key, secret_key=secret_key, host=host, region=region
)
""" Request initialization"""
""" Choose item id(s) """
item_ids = ["059035342X", "B00X4WHP5E", "B00ZV9RDKK"]
""" Choose resources you want from GetItemsResource enum """
""" For more details, refer: https://webservices.amazon.com/paapi5/documentation/get-items.html#resources-parameter """
get_items_resource = [
GetItemsResource.ITEMINFO_TITLE,
GetItemsResource.OFFERS_LISTINGS_PRICE,
]
""" Forming request """
try:
get_items_request = GetItemsRequest(
partner_tag=partner_tag,
partner_type=PartnerType.ASSOCIATES,
marketplace="www.amazon.com",
condition=Condition.NEW,
item_ids=item_ids,
resources=get_items_resource,
)
except ValueError as exception:
print("Error in forming GetItemsRequest: ", exception)
return
try:
""" Sending request """
response = default_api.get_items(get_items_request)
print("API called Successfully")
print("Complete Response:", response)
""" Parse response """
if response.items_result is not None:
print("Printing all item information in ItemsResult:")
response_list = parse_response(response.items_result.items)
for item_id in item_ids:
print("Printing information about the item_id: ", item_id)
if item_id in response_list:
item = response_list[item_id]
if item is not None:
if item.asin is not None:
print("ASIN: ", item.asin)
if item.detail_page_url is not None:
print("DetailPageURL: ", item.detail_page_url)
if (
item.item_info is not None
and item.item_info.title is not None
and item.item_info.title.display_value is not None
):
print("Title: ", item.item_info.title.display_value)
if (
item.offers is not None
and item.offers.listings is not None
and item.offers.listings[0].price is not None
and item.offers.listings[0].price.display_amount is not None
):
print(
"Buying Price: ",
item.offers.listings[0].price.display_amount,
)
else:
print("Item not found, check errors")
if response.errors is not None:
print("\nPrinting Errors:\nPrinting First Error Object from list of Errors")
print("Error code", response.errors[0].code)
print("Error message", response.errors[0].message)
except ApiException as exception:
print("Error calling PA-API 5.0!")
print("Status code:", exception.status)
print("Errors :", exception.body)
print("Request ID:", exception.headers["x-amzn-RequestId"])
except TypeError as exception:
print("TypeError :", exception)
except ValueError as exception:
print("ValueError :", exception)
except Exception as exception:
print("Exception :", exception)
Anybody know how to get it to work?
I am also experiencing the same problem. The problem can be due to several factors.
First is that you are making too many requests. In this case the solution is simple. You limit the number of request by put:
import time
time.sleep(3)
between one request and another. This should be enough.
The second case is like mine or you have not made any sales in the previous 30 days. Amazon doesn't invest money in providing you access to APIs if you don't generate revenue to the platform. In theory, if you receive a purchase from your affiliate link within 48H they should start accepting requests and therefore that error should no longer appear.
Third case, You have reached your maximum daily limit and therefore you have to wait. 12-24H. I advise you to decrease the number of daily requests and increase them slowly to see what your limit is approximately and then adjust accordingly. This is because each affiliate account based on the number of sales has brackets on the number of requests it can make. The more purchases made from your affiliate account the more requests you can make.
Fourth and last case you are already making sales but the same message appears even after a while. In this case you should contact Amazon directly and ask for clarification. maybe there could be some technical problems.