jorgerosal / amazon-paapi

🔥Amazon Product Advertising API for NodeJs. A PAAPI 5.0 sdk wrapper.
https://webservices.amazon.com/paapi5/documentation/
MIT License
80 stars 20 forks source link

bad request (400) when trying to fetch items from multiple marketplaces #14

Closed alonseg closed 3 years ago

alonseg commented 3 years ago

I'm trying to fetch the same items from multiple marketplaces but get a 400 bad request error. sample code:

const commonParameters = {
    AccessKey: 'XXXXXXX',
    SecretKey: 'XXXXXXYYYYYYY',
    PartnerType: 'Associates', // Default value is Associates.
};
const domainParameters = {
        'de': {
            PartnerTag: 'mytag-21', // yourtag-20
            Marketplace: 'www.amazon.de', 
        },
        'fr': {
            PartnerTag: 'mytag-21', // yourtag-20
            Marketplace: 'www.amazon.fr', 
        },
};

function getItems(itemIds) {
      const promisesArr = [];
      Object.values(domainParameters).forEach(domainParam => {
        const amazonPaapi = require('amazon-paapi');
        const commonParams = Object.assign(commonParameters, domainParam);
        const requestParams = Object.assign({ ItemIds: itemIds }, requestParameters);
        promisesArr.push(amazonPaapi
            .GetItems(commonParams, requestParams));
      });
      return promisesArr;
  }

and get the following error

text: '{"__type":"com.amazon.paapi5#InvalidPartnerTagException","Errors":[{"Code":"InvalidPartnerTag","Message":"The partner tag is not mapped to a valid associate store with your access key XXXXXXXX. Please visit associates central at https://partnernet.amazon.de/assoc_credentials/home"}]}',

if I comment out the 'fr' or 'de' config it works, but when running with both, it fails.

alonseg commented 3 years ago

Apologies, it was misuse of async await with forEach, was solved by using for ... of you may please close\delete