0

我一直在尝试使用 Ruby gem 访问新的 Amazon SP-APIamz_sp_api

我已按照有关创建 IAM 用户以及获取我认为正确的令牌的所有说明进行操作。但我继续收到以下错误:

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

这是我正在使用的代码:

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

我得到回报

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"
    }
  ]
}

还有人看到这个问题吗?我经历了设置 IAM 用户和所有这些混乱的广泛的入职流程。

4

1 回答 1

1

这是因为您需要像这样 AmzSpApi::FulfillmentOutboundApiModel::FbaOutboundApi.new(AmzSpApi::SpApiClient.new) 按照https://github.com/ericcj/amz_sp_api#getting-started将客户端传递给 API

于 2021-06-01T15:59:59.163 回答