Skip to content

Commit 6521046

Browse files
committed
added restricted_data_token
1 parent 63534b7 commit 6521046

6 files changed

Lines changed: 46 additions & 4 deletions

File tree

docs/client_usage.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ All endpoint's clients have the following signature and default values:
1616
marketplace=Marketplaces.US, *,
1717
refresh_token=None,
1818
account='default',
19-
credentials=None
19+
credentials=None,
20+
restricted_data_token=None
2021
)

docs/endpoints/orders.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,19 @@ Orders
66

77

88
.. autoclass:: sp_api.api.Orders
9+
10+
11+
12+
Restricted Data Token
13+
=====================
14+
15+
To use a restricted data token to access PII data, you can pass the token obtained from the Token endpoint to the client:
16+
17+
.. code-block:: python
18+
19+
Orders(restricted_data_token='......').get_orders(...)
20+
21+
22+
23+
24+

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='python-amazon-sp-api',
5-
version='0.6.8',
5+
version='0.7.0',
66
install_requires=[
77
"requests",
88
"six>=1.15,<2",

sp_api/base/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def __init__(
2929
*,
3030
refresh_token=None,
3131
account='default',
32-
credentials=None
32+
credentials=None,
33+
restricted_data_token=None
3334
):
3435
super().__init__(account, credentials)
3536
self.boto3_client = boto3.client(
@@ -40,6 +41,7 @@ def __init__(
4041
self.endpoint = marketplace.endpoint
4142
self.marketplace_id = marketplace.marketplace_id
4243
self.region = marketplace.region
44+
self.restricted_data_token = restricted_data_token
4345
self._auth = AccessTokenClient(refresh_token=refresh_token, account=account, credentials=credentials)
4446

4547
def _get_cache_key(self, token_flavor=''):
@@ -61,7 +63,7 @@ def headers(self):
6163
return {
6264
'host': self.endpoint[8:],
6365
'user-agent': self.user_agent,
64-
'x-amz-access-token': self.auth.access_token,
66+
'x-amz-access-token': self.restricted_data_token or self.auth.access_token,
6567
'x-amz-date': datetime.utcnow().strftime('%Y%m%dT%H%M%SZ'),
6668
'content-type': 'application/json'
6769
}

tests/api/tokens/__init__.py

Whitespace-only changes.

tests/api/tokens/test_tokens.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from datetime import timedelta, datetime
2+
3+
import pytest
4+
5+
from sp_api.api import Tokens, Orders
6+
from sp_api.base import SellingApiBadRequestException, Marketplaces
7+
8+
#
9+
# def test_get_token_for_bulk_orders():
10+
# with pytest.raises(SellingApiBadRequestException) as info:
11+
# res = Tokens().create_restricted_data_token(restrictedResources=[
12+
# {
13+
# "method": "GET",
14+
# "path": "/orders/v0/orders",
15+
# "dataElements": ["buyerInfo", "shippingAddress"]
16+
# }
17+
# ])
18+
# print(res)
19+
#
20+
#
21+
# def test_get_order_with_token():
22+
# res = Orders(restricted_data_token='foo').get_orders(CreatedAfter=(datetime.now() - timedelta(days=10)).isoformat())
23+
# print(res)

0 commit comments

Comments
 (0)