ericcj/amz_sp_api

get_authorization_code - refresh_token missing?

Opened this issue · 3 comments

I appreciate that it is early days for this gem, but, I'm excited by the potential of it!

I need to figure out the first steps - i.e. either direct LWA access or using our existing MWS auth tokens to access data. So I am looking at the get_authorization_code call, which should convert an existing mws auth token into an lws token.

I use the code from the read me to set up my config block:

require 'amz_sp_api'
require 'fulfillment-outbound-api-model'
require 'authorization-api-model'

AmzSpApi.configure do |config|
  # config.refresh_token = nil <- this should not be needed for this call
  config.client_id = 'amzn1.application-oa2-client.xxxxxxxx'
  config.client_secret = 'xxxxxx'

  # either use these:
  config.aws_access_key_id = 'xxxx'
  config.aws_secret_access_key = 'xxx+xxx'

  config.region = 'eu'
  config.timeout = 20 # seconds
  config.debugging = true

  # optional lambdas for caching LWA access token instead of requesting it each time, e.g.:
  config.save_access_token = lambda { |access_token_key, token|
    Rails.cache.write("SPAPI-TOKEN-#{access_token_key}", token[:access_token], expires_in: token[:expires_in] - 60)
  }
  config.get_access_token = ->(access_token_key) { Rails.cache.read("SPAPI-TOKEN-#{access_token_key}") }
end

and then do:

api = AmzSpApi::AuthorizationApiModel::AuthorizationApi.new(AmzSpApi::SpApiClient.new)
api.get_authorization_code seller_id, eu_dev_id, mws_auth_token

I get back this:

AmzSpApi::ApiError (Error message: the server returns an error)
HTTP status code: 400
Response headers: {"Server"=>"Server", "Date"=>"Sun, 06 Jun 2021 00:02:12 GMT", "Content-Type"=>"application/json;charset=UTF-8", "Content-Length"=>"109", "Connection"=>"keep-alive", "x-amz-rid"=>"xxxx", "x-amzn-RequestId"=>"xxxx-0ece-4eb0-802c-xxxx", "X-Amz-Date"=>"Sun, 06 Jun 2021 00:02:12 GMT", "x-amzn-ErrorType"=>"OA2InvalidRequestException:http://internal.amazon.com/coral/com.amazon.panda/", "Cache-Control"=>"no-cache, no-store, must-revalidate", "Pragma"=>"no-cache", "Vary"=>"Content-Type,Accept-Encoding,X-Amzn-CDN-Cache,X-Amzn-AX-Treatment,User-Agent", "Permissions-Policy"=>"interest-cohort=()"}
Response body: {"error_description":"The request is missing a required parameter : refresh_token","error":"invalid_request"}

I am not sure how this call SHOULD work (actually examples of using the SP-API seem thin on the ground), but I don't think it should be using the refresh_token (especially when it is nil)

ya i haven't implemented "grantless operations" in this gem but would welcome the contribution: #3 (comment)

For Feeds API i'm getting following error on

2.4.3 :034 > response = feeds.create_feed_document({"contentType" => 'JSON_LISTINGS_FEED'})

85", "x-amzn-ErrorType"=>"AccessDeniedException", "x-amz-apigw-id"=>"GsklMFiJjoEF5DQ="}
Response body: {
"errors": [
{
"message": "Access to requested resource is denied.",
"code": "Unauthorized",
"details": ""
}
]
}

Any thought?

Thanks :)

@AteqEjaz Late answer but your issue is unrelated I think so you should open a new one.