amz-tools / amazon-sp-api

Amazon Selling Partner API Client
MIT License
231 stars 119 forks source link

CustomError: Access to requested resource is denied. #32

Closed kevinhq closed 3 years ago

kevinhq commented 3 years ago

Hi,

Any idea with this error:

CustomError: Access to requested resource is denied.
    at SellingPartner.callAPI (/Users/k/node_modules/amazon-sp-api/lib/SellingPartner.js:503:13)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at async /Users/k/Y/Lister/amz-sp-api-node.js:17:15 {
  code: 'Unauthorized',
  details: '',
  type: 'error'
}

Here are the codes we use:

const SellingPartnerAPI = require("amazon-sp-api"); 

(async () => {
  try {
    console.log(process.env);
    let sellingPartner = new SellingPartnerAPI({
      region: "na",
      refresh_token: process.env.AMZ_SP_API_REFRESH_TOKEN,
      credentials: {
        SELLING_PARTNER_APP_CLIENT_ID: process.env.SELLING_PARTNER_APP_CLIENT_ID,
        SELLING_PARTNER_APP_CLIENT_SECRET: process.env.SELLING_PARTNER_APP_CLIENT_SECRET,
        AWS_ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID,
        AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY,
        AWS_SELLING_PARTNER_ROLE: process.env.AWS_SELLING_PARTNER_ROLE
      },
    });
    let res = await sellingPartner.callAPI({
      operation:'getMarketplaceParticipations'
    });
    console.log(res);
  } catch (e) {
    console.log(e);
  }
})();

We tried other operations too, but all of them return the same error. We can access the MWS API just fine. But, we don't have active Amazon Seller Account (is this an issue?)

amz-tools commented 3 years ago

HI @kevinhq,

could be that one of the config params is wrong (either the token or one of the credentials), but I would rather go with the inactive seller account explanation. It is definitely required to have a professional seller account and I'd guess that requires the account to be active as well.

What is weird though: The same applies to the MWS API, so its strange that you can access MWS if the inactive seller account is the explanation. Guess the easiest way is to open a case with Amazon and ask them directly.

One more thing about the code: If you already provide the credentials as env variables you can skip defining them in the constructor config object.

kevinhq commented 3 years ago

Guess the easiest way is to open a case with Amazon and ask them directly.

We tried but Amazon just close the case with the reason we have no active Amazon seller account. To be honest, the same error goes with the Ruby implementation.

Ok, I'll ask the product owner about activating their Amazon seller account.