ericcj/amz_sp_api

Orders api returns nil but with status 200.

talhaijaz opened this issue · 2 comments

I have integrated amazon sp-api with my rails application successfully but the issue is When i try to fetch orders from client's UK sellers account it returns nil in orders but there are orders in UK seller account.
Note: The developer app is in UK seller account and my app is in draft state but i generate a refresh token for UK through authorize button.
Sample Response:
[nil, 200, {"date"=>"Wed, 13 Oct 2021 21:01:58 GMT", "content-type"=>"application/json", "content-length"=>"1170", "x-amzn-requestid"=>"amazonrequestID", "x-amzn-ratelimit-limit"=>"0.0167", "x-amz-apigw-id"=>"fd=", "x-amzn-trace-id"=>"Root=traceid"}]

Did you manage to get anywhere with this? @talhaijaz

Hey @jakemcallister thanks for responding yes i resolved the issue after authenticating Amazon app and changing the region while initializing Amazon sp api i got all the orders from Amazon.

AmzSpApi.configure do |config|
config.refresh_token = ecommerce_provider.app_refresh_token
config.client_id = ecommerce_provider.app_client_id
config.client_secret = ecommerce_provider.app_client_secret
config.aws_access_key_id = ecommerce_provider.amazon_access_key
config.aws_secret_access_key = ecommerce_provider.amazon_secret_key

    config.region = 'na'
    config.timeout = 20 # seconds

    config.save_access_token = -> (access_token_key, token) do
      Rails.cache.write("SPAPI-TOKEN-#{access_token_key}", token[:access_token], expires_in: token[:expires_in] - 60)
    end
    config.get_access_token = -> (access_token_key) { Rails.cache.read("SPAPI-TOKEN-#{access_token_key}") }
  end
 api_client = AmzSpApi::SpApiClient.new

AmzSpApi::OrdersApiModel::OrdersV0Api.new(api_client) // will fetch the orders for you