I am trying to fetch the data from amazon store by using amazon paapi5.0 but it always gives me error 429. which is too many requests per second.
I tried to run this thing in amazon scratch pad but it is giving back as also same error.
Below here I am attaching the screenshot of the scratchpad error
Also I am facing same problem with the implementation of the code in java script. The error and the code snippet I am attaching below please help me to resolve issue.
The code
/**
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
// Run `npm install` locally before executing following code with `node sampleGetItemsApi.js`
/**
* This sample code snippet is for ProductAdvertisingAPI 5.0's GetItems API
* For more details, refer:
* https://webservices.amazon.com/paapi5/documentation/get-items.html
*/
var ProductAdvertisingAPIv1 = require('./src/index');
var defaultClient = ProductAdvertisingAPIv1.ApiClient.instance;
// Specify your credentials here. These are used to create and sign the request.
defaultClient.accessKey = 'my access key here';
defaultClient.secretKey = 'my screte key';
/**
* 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
*/
defaultClient.host = 'webservices.amazon.com';
defaultClient.region = 'us-east-1';
var api = new ProductAdvertisingAPIv1.DefaultApi();
// Request Initialization
var getItemsRequest = new ProductAdvertisingAPIv1.GetItemsRequest();
/** Enter your partner tag (store/tracking id) and partner type */
getItemsRequest['PartnerTag'] = 'my Partner tag';
getItemsRequest['PartnerType'] = 'Associates';
/** Enter the Item IDs for which item information is desired */
getItemsRequest['ItemIds'] = ['059035342X'];
getItemsRequest['Condition'] = 'New';
/**
* Choose resources you want from GetItemsResource enum
* For more details, refer: https://webservices.amazon.com/paapi5/documentation/get-items.html#resources-parameter
*/
getItemsRequest['Resources'] = ['Images.Primary.Medium', 'ItemInfo.Title', 'Offers.Listings.Price'];
/**
* Function to parse GetItemsResponse into an object with key as ASIN
*/
function parseResponse(itemsResponseList) {
var mappedResponse = {};
for (var i in itemsResponseList) {
if (itemsResponseList.hasOwnProperty(i)) {
mappedResponse[itemsResponseList[i]['ASIN']] = itemsResponseList[i];
}
}
return mappedResponse;
}
function onSuccess(data) {
console.log('API called successfully.');
var getItemsResponse = ProductAdvertisingAPIv1.GetItemsResponse.constructFromObject(data);
console.log('Complete Response: n' + JSON.stringify(getItemsResponse, null, 1));
if (getItemsResponse['ItemsResult'] !== undefined) {
console.log('Printing All Item Information in ItemsResult:');
var response_list = parseResponse(getItemsResponse['ItemsResult']['Items']);
for (var i in getItemsRequest['ItemIds']) {
if (getItemsRequest['ItemIds'].hasOwnProperty(i)) {
var itemId = getItemsRequest['ItemIds'][i];
console.log('nPrinting information about the Item with Id: ' + itemId);
if (itemId in response_list) {
var item = response_list[itemId];
if (item !== undefined) {
if (item['ASIN'] !== undefined) {
console.log('ASIN: ' + item['ASIN']);
}
if (item['DetailPageURL'] !== undefined) {
console.log('DetailPageURL: ' + item['DetailPageURL']);
}
if (
item['ItemInfo'] !== undefined &&
item['ItemInfo']['Title'] !== undefined &&
item['ItemInfo']['Title']['DisplayValue'] !== undefined
) {
console.log('Title: ' + item['ItemInfo']['Title']['DisplayValue']);
}
if (
item['Offers'] !== undefined &&
item['Offers']['Listings'] !== undefined &&
item['Offers']['Listings'][0]['Price'] !== undefined &&
item['Offers']['Listings'][0]['Price']['DisplayAmount'] !== undefined
) {
console.log('Buying Price: ' + item['Offers']['Listings'][0]['Price']['DisplayAmount']);
}
}
} else {
console.log('Item not found, check errors');
}
}
}
}
if (getItemsResponse['Errors'] !== undefined) {
console.log('nErrors:');
console.log('Complete Error Response: ' + JSON.stringify(getItemsResponse['Errors'], null, 1));
console.log('Printing 1st Error:');
var error_0 = getItemsResponse['Errors'][0];
console.log('Error Code: ' + error_0['Code']);
console.log('Error Message: ' + error_0['Message']);
}
}
function onError(error) {
console.log('Error calling PA-API 5.0!');
console.log('Printing Full Error Object:n' + JSON.stringify(error, null, 1));
console.log('Status Code: ' + error['status']);
if (error['response'] !== undefined && error['response']['text'] !== undefined) {
console.log('Error Object: ' + JSON.stringify(error['response']['text'], null, 1));
}
}
api.getItems(getItemsRequest).then(
function(data) {
onSuccess(data);
},
function(error) {
onError(error);
}
);
The error response I am getting
Error calling PA-API 5.0!
Printing Full Error Object:
{
"status": 429,
"response": {
"req": {
"method": "POST",
"url": "https://webservices.amazon.com/paapi5/getitems",
"data": {
"ItemIds": [
"059035342X"
],
"PartnerTag": "zserfv45-21",
"PartnerType": "Associates",
"Condition": "New",
"Resources": [
"Images.Primary.Medium",
"ItemInfo.Title",
"Offers.Listings.Price"
]
},
"headers": {
"user-agent": "paapi5-nodejs-sdk/1.0.0",
"authorization": "AWS4-HMAC-SHA256 Credential=AKIAIGIUBJ2E4NJEZW3A/20230423/us-east-1/ProductAdvertisingAPI/aws4_request, SignedHeaders=content-encoding;content-type;host;x-amz-date;x-amz-target, Signature=033005cd9cc72e2fce23e4d331924d0752230fd50cba07c215edd7598638974e",
"content-encoding": "amz-1.0",
"content-type": "application/json; charset=utf-8",
"host": "webservices.amazon.com",
"x-amz-target": "com.amazon.paapi5.v1.ProductAdvertisingAPIv1.GetItems",
"x-amz-date": "20230423T062343Z",
"accept": "application/json"
}
},
"header": {
"server": "Server",
"date": "Sun, 23 Apr 2023 06:23:45 GMT",
"content-type": "application/json",
"content-length": "247",
"connection": "close",
"x-amz-rid": "ZWZPMJFE2FGXPCBWRQQF",
"x-amzn-requestid": "284f73c9-e2e4-4438-adc8-da2673b7bf60",
"vary": "Content-Type,Accept-Encoding,User-Agent",
"strict-transport-security": "max-age=47474747; includeSubDomains; preload"
},
"status": 429,
"text": "{"__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."}]}"
}
}
Status Code: 429
Error Object: "{"__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."}]}"
I tried same request sending like 40-50 times but no improvement.