Last active
November 29, 2022 22:17
-
-
Save chespinoza/43e4a98375f57168994b37aa3e858897 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
from urllib.parse import urlencode | |
import requests | |
from nozzle.spapi.client import REGIONS, create_sigv4_session | |
NA_AUTH_URI = "https://api.amazon.com/auth/o2/token" | |
EU_AUTH_URI = "https://api.amazon.co.uk/auth/o2/token" | |
FE_AUTH_URI = "https://api.amazon.co.jp/auth/o2/token" | |
CLIENT_ID = "" | |
CLIENT_SECRET = "" | |
ACCESS_KEY = "" | |
SECRET_KEY = "" | |
DEVELOPER_ID = "" | |
SELLING_PARTNER_ID = "" | |
MWS_AUTH_TOKEN = "" | |
if __name__ == "__main__": | |
# Get a Grantless access token | |
params = { | |
"grant_type": "client_credentials", | |
"client_id": CLIENT_ID, | |
"client_secret": CLIENT_SECRET, | |
"scope": "sellingpartnerapi::notifications sellingpartnerapi::migration", | |
} | |
res = requests.post(NA_AUTH_URI, json=params) | |
access_token = res.json().get("access_token") | |
if not access_token: | |
print(res.headers) | |
print(res.text) | |
quit() | |
# Exchange MWS token | |
sp_api_region = REGIONS["NA"].aws_region | |
session = create_sigv4_session( | |
access_key=ACCESS_KEY, secret_key=SECRET_KEY, spapi_region=sp_api_region | |
) | |
params = { | |
"sellingPartnerId": SELLING_PARTNER_ID, | |
"developerId": DEVELOPER_ID, | |
"mwsAuthToken": MWS_AUTH_TOKEN, | |
} | |
response = session.request( | |
"GET", | |
f"https://sellingpartnerapi-na.amazon.com/authorization/v1/authorizationCode", | |
headers={ | |
"x-amz-access-token": access_token, | |
}, | |
params=params, | |
) | |
print(response.headers) | |
print(response.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment