ericcj/amz_sp_api

Support for Restricted Operations

Closed this issue · 5 comments

Certain operations require a Restricted Data Token (RDT):
https://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/use-case-guides/tokens-api-use-case-guide/tokens-API-use-case-guide-2021-03-01.md#restricted-operations

Is there a way to include a RDT instead of a LWA access token in the x-amz-access-token header ?

There is not currently but would welcome a contribution

After fetching an RDT, you can pass an options hash to get_order() to do that. This works for me:

api_tokens = AmzSpApi::TokensApiModel::TokensApi.new(client)
body = {
  'restrictedResources' => [
    {
      'method' => 'GET',
      'path' => "/orders/v0/orders/#{my_order_id}",
      'dataElements' => ['buyerInfo', 'shippingAddress']
    }
  ]
}
response = api_tokens.create_restricted_data_token(body)
my_rdt = response.restricted_data_token
api_orders = AmzSpApi::OrdersApiModel::OrdersV0Api.new(client)
order = api_orders.get_order(my_order_id, {header_params: {'x-amz-access-token' => my_rdt}})
puts order.pretty_inspect

Do you still need to request permission for generating RDT's even for your own application (not for public facing apps)?

After fetching an RDT, you can pass an options hash to get_order() to do that. This works for me:

api_tokens = AmzSpApi::TokensApiModel::TokensApi.new(client)
body = {
  'restrictedResources' => [
    {
      'method' => 'GET',
      'path' => "/orders/v0/orders/#{my_order_id}",
      'dataElements' => ['buyerInfo', 'shippingAddress']
    }
  ]
}
response = api_tokens.create_restricted_data_token(body)
my_rdt = response.restricted_data_token
api_orders = AmzSpApi::OrdersApiModel::OrdersV0Api.new(client)
order = api_orders.get_order(my_order_id, {header_params: {'x-amz-access-token' => my_rdt}})
puts order.pretty_inspect

I confirm this works, thank you

ericcj commented

i did this in #55