python-amazon-sp-api icon indicating copy to clipboard operation
python-amazon-sp-api copied to clipboard

next_token fix for VendorOrders

Open AndreiFAD opened this issue 3 years ago • 2 comments

Hi!

Describe the bug I never get the next page. It only worked for me with the following solution(picture) (I made a fork, about the modification) https://github.com/AndreiFAD/python-amazon-sp-api/tree/next_token -> https://github.com/AndreiFAD/python-amazon-sp-api/commit/73c89216dbf7e6e1f31c0d7cfb54756f66727312

from sp_api.util import throttle_retry, load_all_pages

@throttle_retry()
@load_all_pages()
def get_purchase_orders(**kwargs):
    """
    a generator function to return all pages, obtained by NextToken
    """
    return VendorOrders(credentials=get_amz_credentials(profile_name), marketplace=Marketplaces.XX).get_purchase_orders(**kwargs)

df_list = []
for item in get_purchase_orders(createdAfter=(datetime.now() - timedelta(days=20)).isoformat()):
    df_list.append(pd.DataFrame.from_records(item.payload['orders']))
df = pd.concat(df_list)

Desktop (please complete the following information):

  • OS: Mac

Additional context

image

new position for nextToken (https://github.com/amzn/selling-partner-api-models/blob/main/models/vendor-orders-api-model/vendorOrders.json):

'payload' -> 'pagination' -> 'nextToken'

{'errors': None,
 'headers': {'Date': 'Sat, 13 Aug 2022 21:10:41 GMT', 'Content-Type': 'application/json', 'Content-Length': '54545', 'Connection': 'keep-alive', 'x-amzn-RequestId': 'b906353536a653235535f6c5a583', 'x-amzn-RateLimit-Limit': '10.0', 'x-amz-apigw-id': '235wrty23545235=', 'X-Amzn-Trace-Id': 'Root=1-62f81351-4ac4235233483857837h6e34'},
 'kwargs': {},
 'next_token': None,
 'pagination': None,
 'payload': {'ordersStatus': [],
             'pagination': {'nextToken': 'WzE2NTU2wNzsffk4NDkwMDAsIjM0TzNMTjRYIl0'}},
 'rate_limit': '10.0'}

AndreiFAD avatar Aug 13 '22 22:08 AndreiFAD

Thanks for reporting this. Can you create a PR to account for this?

saleweaver avatar Aug 14 '22 16:08 saleweaver

sure, I created: https://github.com/saleweaver/python-amazon-sp-api/pull/684 but I got an error: AWS CodeBuild eu-central-1 (python-sp-api-on-pr) — Build failed for project python-sp-api-on-pr

AndreiFAD avatar Aug 14 '22 17:08 AndreiFAD