question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use restrictedDataToken in Orders().get_orders() ?

See original GitHub issue

I have created restrictedDataToken according to this guide 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#tutorial-get-buyer-and-shipping-address-information-for-bulk-orders

body = {
    "restrictedResources": [
        {
            "method": "GET",
            "path": "/orders/v0/orders",
            "dataElements": ["buyerInfo", "shippingAddress"]
        }
    ]
}

tokens_api = Tokens(credentials=credentials)
response = tokens_api.create_restricted_data_token(restrictedResources=body)
restrictedDataToken = response.payload['restrictedDataToken']

But I don’t know how to use restrictedDataToken in Orders() endpoint

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
sinancetinkayacommented, Aug 18, 2021

The code below works fine. Please consider adding headers (or better way you think of) in the endpoints

from sp_api.api import Orders, Tokens
from sp_api.base import ApiResponse, sp_endpoint

class MyOrders(Orders):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    @sp_endpoint('/orders/v0/orders')
    def get_orders(self, **kwargs) -> ApiResponse:
        headers = kwargs.pop('headers') if 'headers' in kwargs else None
        return self._request(kwargs.pop('path'), params={**kwargs}, headers=headers)


credentials = {...}
AmazonOrderIds = [...]

tokens_api = Tokens(credentials=credentials)
response = tokens_api.create_restricted_data_token(
    restrictedResources=[
        {
            "method": "GET",
            "path": "/orders/v0/orders",
            "dataElements": ["buyerInfo", "shippingAddress"]
        }
    ]
)
restrictedDataToken = response.payload['restrictedDataToken']

orders_api = MyOrders(credentials=credentials)

response = orders_api.get_orders(
    AmazonOrderIds=",".join(AmazonOrderIds),
    headers={'x-amz-access-token': restrictedDataToken}
)
0reactions
LuisB2904commented, Oct 7, 2021

With the code from @sinancetinkaya i get this error:

sp_api.base.exceptions.SellingApiServerException: [{‘message’: ‘We encountered an internal error. Please try again.’, ‘code’: ‘InternalFailure’}]

does someone have the same error?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use Restricted Data Token (RDT) in Amazon SP Api ...
I tried to use RDT as shown below but it is not working. // Build orders-api OrdersV0Api ordersApi = new OrdersV0Api.Builder() .
Read more >
Restricted Data Token help · Issue #639 - GitHub
I've added a header to the APIClient from OrdersV0Api using ApiClient apic = api.getApiClient().addDefaultHeader("x-amz-access-token", rdt) and ...
Read more >
Call Restricted Operations using Tokens API - YouTube
Find out what restricted operations are and how to get and use Restricted Data Tokens to call them.Check out more Seller University on ......
Read more >
Tokens API Use Case Guide
How to use the Restricted Data Token for secure access to Selling Partner APIs. ... Call the getOrders operation of the Orders API,...
Read more >
Tokens — PYTHON-AMAZON-SP-API documentation
Returns a Restricted Data Token (RDT) for one or more restricted resources that you specify. A restricted resource is the HTTP method and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found