ericcj/amz_sp_api

Always get MissingAuthenticationToken

Closed this issue · 1 comments

I've followed all the directions on creating an IAM user as well as getting what I believe are the correct tokens.. But I continue to get the following error:

"message": "Access to requested resource is denied.",
"code": "MissingAuthenticationToken"

This is the code I'm using:

require 'amz_sp_api'
require 'product-pricing-api-model'
require 'fulfillment-outbound-api-model'
require 'byebug'
require 'aws-sdk-core'

  AmzSpApi.configure do |config|
    config.refresh_token = 'long string'
    config.client_id = 'amzn1.application-oa2-client.123'
    config.client_secret = 'secret'
    config.credentials_provider = Aws::STS::Client.new(
        region: AmzSpApi::SpConfiguration::AWS_REGION_MAP['na'],
        access_key_id: 'key',
        secret_access_key: 'secret_key'
      ).assume_role(role_arn: 'arn:aws:iam::123:role/SellerAPIRole', role_session_name: SecureRandom.uuid)

    config.timeout = 20 # seconds
    config.debugging = true
  end

api_instance = AmzSpApi::FulfillmentOutboundApiModel::FbaOutboundApi.new
marketplace_id = 'ATVPDKIKX0DER'

begin
  result = api_instance.get_features(marketplace_id)
  pp result
rescue AmzSpApi::FulfillmentOutboundApiModel::ApiError => e
  puts "Exception when calling FbaOutboundApi->get_features: #{e}"
end

And I get in return

Exception when calling FbaOutboundApi->get_features: Error message: the server returns an error
HTTP status code: 403
Response headers: {"Date"=>"Wed, 12 May 2021 19:23:39 GMT", "Content-Type"=>"application/json", "Content-Length"=>"135", "Connection"=>"keep-alive", "x-amzn-RequestId"=>"123", "x-amzn-ErrorType"=>"MissingAuthenticationTokenException", "x-amz-apigw-id"=>"something"}
Response body: {
  "errors": [
    {
      "message": "Access to requested resource is denied.",
     "code": "MissingAuthenticationToken"
    }
  ]
}

Anyone else seeing this issue? I've gone through the extensive onboarding process of setting up a IAM user and all that mess.

this is because you need to pass the client to the api like this AmzSpApi::FulfillmentOutboundApiModel::FbaOutboundApi.new(AmzSpApi::SpApiClient.new) as per https://github.com/ericcj/amz_sp_api#getting-started