[OrdersAPI] Problem: "Application does not have access to one or more requested data elements: [shippingAddress]"
gugglegum opened this issue · comments
Hi!
I've read a ton of docs and other issues here and know that this is a very common problem. In most cases, people simply do not know that in order to access restricted information they need to obtain special permission from Amazon, which is very difficult to obtain. It took us a year to get this permit, having previously received several refusals.
The following code for receiving RDT (Restricted Data Token) works for me and I receive a real token:
$tokensApi = new TokensV20210301Api($amazonConfig);
$result = $tokensApi->createRestrictedDataToken(new \SellingPartnerApi\Model\TokensV20210301\CreateRestrictedDataTokenRequest([
'restricted_resources' => [
new \SellingPartnerApi\Model\TokensV20210301\RestrictedResource([
'method' => 'GET',
'path' => '/orders/v0/orders',
'dataElements' => ['buyerInfo', 'shippingAddress'],
]),
],
]));
var_dump($result->getRestrictedDataToken());
But what to do with it next? Where should I send it? The getOrders()
method does not accept RDT. According to the README file, the library itself automatically creates and substitutes an RDT token when requesting restricted information.
$ordersApi = new OrdersV0Api($amazonConfig);
$response = $ordersApi->getOrders(
marketplace_ids: [$this->amazonMarketplaceId],
created_after: $this->createdAfterDate?->toIso8601ZuluString(),
created_before: $this->createdBeforeDate?->toIso8601ZuluString(),
last_updated_after: $this->updatedAfterDate?->toIso8601ZuluString(),
last_updated_before: $this->updatedBeforeDate?->toIso8601ZuluString(),
order_statuses: $this->statuses ?? null,
fulfillment_channels: $this->fulfillmentChannels ?? null,
max_results_per_page: 100,
next_token: $this->nextToken,
amazon_order_ids: $this->amazonOrderIds ?? null,
data_elements: ['buyerInfo', 'shippingAddress']
);
But when I try to get orders with PII in this way, I get rejected:
Error: Amazon #1: Failed to create restricted data token: [400] {
"errors": [
{
"code": "InvalidInput",
"message": "Application does not have access to one or more requested data elements: [shippingAddress]",
"details": ""
}
]
}
So I'm confused: either there's something wrong with the access in Amazon (but then why is the RDT token being created directly via Tokens API?), or something wrong with this library (but then why isn't anyone complaining?), or I'm doing something wrong. The $amazonConfig
is the same in both examples.
I found a mistake in my first example where I'm creating RDT. Need:
'data_elements' => ['buyerInfo', 'shippingAddress'],
instead of
'dataElements' => ['buyerInfo', 'shippingAddress'],
Now I'm getting the same error in both examples which means that the problem not in this library.
I'm sorry. Seems we still did not get PII access. The "Direct-to-Consumer Shipping" is unchecked in Developer profile. :(