jorgerosal / amazon-paapi

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

401 using example code #13

Closed ralyodio closed 3 years ago

ralyodio commented 3 years ago

I'm getting 401 with example script.

const amazonPaapi = require('amazon-paapi');
const ck = require('ckey'); // access .env variables

console.log(ck);

const commonParameters = {
  'AccessKey'  : ck.AWS_ACCESS_KEY,
  'SecretKey'  : ck.AWS_SECRET_KEY,
  'PartnerTag' : ck.AWS_TAG, // yourtag-20
  'PartnerType': 'Associates', //  Default value is Associates. 
  'Marketplace': 'www.amazon.com' // Default value is US. Note: Host and Region are predetermined based on the marketplace value. There is no need for you to add Host and Region as soon as you specify the correct Marketplace value. If your region is not US or .com, please make sure you add the correct Marketplace value.
}

const requestParameters = {
    'Keywords' : 'rust programming',
    'SearchIndex' : 'Books',
    'ItemCount' : 2,
    'Resource': ['Images.Primary.Medium', 'ItemInfo.Title', 'Offers.Listings.Price']
};

/** Promise */
amazonPaapi.SearchItems(commonParameters, requestParameters)
    .then(data => {
        // do something with the success response.
        console.log(data);
    })
    .catch(error => {
        // catch an error.
        console.log(error)
    });
      text: '{"__type":"com.amazon.paapi5#InvalidSignatureException","Errors":[{"Code":"InvalidSignature","Message":"The request has not been correctly signed. If you are using an AWS SDK, requests are signed for you automatically; otherwise, go to https://webservices.amazon.com/paapi5/documentation/sending-request.html#signing."}]}',
      [Symbol(kCapture)]: false,
      [Symbol(RequestTimeout)]: undefined
    },
jorgerosal commented 3 years ago

Hi @chovy, your code sample above works fine on my end with my own credential. Please try and review your credentials inside .env file and make sure it's correct. Thank you.

{"SearchResult":{"TotalResultCount":237,"SearchURL":"https://www.amazon.com/s?k=rust+programming&i=stripbooks&rh=p_n_availability%3A-1&tag=test-20&linkCode=osi","Items":[{"ASIN":"1718500440","DetailPageURL":"https://www.amazon.com/dp/1718500440?tag=test-20&linkCode=osi&th=1&psc=1","ItemInfo":{"Title":{"DisplayValue":"The Rust Programming Language (Covers Rust 2018)","Label":"Title","Locale":"en_US"}}},{"ASIN":"1492052590","DetailPageURL":"https://www.amazon.com/dp/1492052590?tag=test-20&linkCode=osi&th=1&psc=1","ItemInfo":{"Title":{"DisplayValue":"Programming Rust: Fast, Safe Systems 
Development","Label":"Title","Locale":"en_US"}}}]}}