Certain Amazon SP-API operations return Personally Identifiable Information (PII), such as buyer names or shipping addresses. To access these, you must exchange your standard access_token for a Restricted Data Token (RDT) scoped to specific resources.
1. Create the RDT
Use the Peddler.tokens API to request an RDT. You must specify the HTTP method, the path, and for Orders, the required dataElements (e.g., buyerInfo, shippingAddress).
api = Peddler.tokens.new(aws_region, access_token)
response = api.create_restricted_data_token({
"restrictedResources" => [
{
"method" => "GET",
"path" => "/orders/v0/orders",
"dataElements" => ["buyerInfo", "shippingAddress"],
},
],
})
restricted_data_token = response.parse.restricted_data_token
2. Use the RDT
Pass the restricted_data_token in place of the access_token when initializing the target API client.
api = Peddler.orders.new(aws_region, restricted_data_token)
address = api.get_order_address("123-1234567-1234567").parse.payload.shipping_address
RDTs are valid for one hour and should be cached.
api = Peddler.tokens.new(aws_region, access_token)
response = api.create_restricted_data_token({
"restrictedResources" => [
{
"method" => "GET",
"path" => "/orders/v0/orders/123-1234567-1234567/address",
},
],
})
restricted_data_token = response.parse.restricted_data_token