Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_authorization_code - refresh_token missing? #6

Open
philsmy opened this issue Jun 6, 2021 · 3 comments
Open

get_authorization_code - refresh_token missing? #6

philsmy opened this issue Jun 6, 2021 · 3 comments

Comments

@philsmy
Copy link

philsmy commented Jun 6, 2021

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)

@ericcj
Copy link
Owner

ericcj commented Jun 18, 2021

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

@AteqEjaz
Copy link

AteqEjaz commented Oct 4, 2021

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 :)

@philsmy
Copy link
Author

philsmy commented Aug 6, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants