Skip to content

Commit

Permalink
added restricted_data_token
Browse files Browse the repository at this point in the history
  • Loading branch information
saleweaver committed Oct 19, 2021
1 parent 63534b7 commit 6521046
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 4 deletions.
3 changes: 2 additions & 1 deletion docs/client_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ All endpoint's clients have the following signature and default values:
marketplace=Marketplaces.US, *,
refresh_token=None,
account='default',
credentials=None
credentials=None,
restricted_data_token=None
)
16 changes: 16 additions & 0 deletions docs/endpoints/orders.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,19 @@ Orders


.. autoclass:: sp_api.api.Orders



Restricted Data Token
=====================

To use a restricted data token to access PII data, you can pass the token obtained from the Token endpoint to the client:

.. code-block:: python
Orders(restricted_data_token='......').get_orders(...)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='python-amazon-sp-api',
version='0.6.8',
version='0.7.0',
install_requires=[
"requests",
"six>=1.15,<2",
Expand Down
6 changes: 4 additions & 2 deletions sp_api/base/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def __init__(
*,
refresh_token=None,
account='default',
credentials=None
credentials=None,
restricted_data_token=None
):
super().__init__(account, credentials)
self.boto3_client = boto3.client(
Expand All @@ -40,6 +41,7 @@ def __init__(
self.endpoint = marketplace.endpoint
self.marketplace_id = marketplace.marketplace_id
self.region = marketplace.region
self.restricted_data_token = restricted_data_token
self._auth = AccessTokenClient(refresh_token=refresh_token, account=account, credentials=credentials)

def _get_cache_key(self, token_flavor=''):
Expand All @@ -61,7 +63,7 @@ def headers(self):
return {
'host': self.endpoint[8:],
'user-agent': self.user_agent,
'x-amz-access-token': self.auth.access_token,
'x-amz-access-token': self.restricted_data_token or self.auth.access_token,
'x-amz-date': datetime.utcnow().strftime('%Y%m%dT%H%M%SZ'),
'content-type': 'application/json'
}
Expand Down
Empty file added tests/api/tokens/__init__.py
Empty file.
23 changes: 23 additions & 0 deletions tests/api/tokens/test_tokens.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from datetime import timedelta, datetime

import pytest

from sp_api.api import Tokens, Orders
from sp_api.base import SellingApiBadRequestException, Marketplaces

#
# def test_get_token_for_bulk_orders():
# with pytest.raises(SellingApiBadRequestException) as info:
# res = Tokens().create_restricted_data_token(restrictedResources=[
# {
# "method": "GET",
# "path": "/orders/v0/orders",
# "dataElements": ["buyerInfo", "shippingAddress"]
# }
# ])
# print(res)
#
#
# def test_get_order_with_token():
# res = Orders(restricted_data_token='foo').get_orders(CreatedAfter=(datetime.now() - timedelta(days=10)).isoformat())
# print(res)

0 comments on commit 6521046

Please sign in to comment.