Skip to content

Instantly share code, notes, and snippets.

@chespinoza
Created March 19, 2022 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chespinoza/054f966152e225bca919806eb7c78997 to your computer and use it in GitHub Desktop.
Save chespinoza/054f966152e225bca919806eb7c78997 to your computer and use it in GitHub Desktop.
import requests
from datetime import datetime
from requests_aws4auth import AWS4Auth
endpoint = "https://sellingpartnerapi-na.amazon.com"
TOKEN_URL = "https://sellingpartnerapi-na.amazon.com/authorization/v1/authorizationCode"
ACCESS_ID = ""
SECRET_ID = ""
if __name__ == "__main__":
params = {
"grant_type": "client_credentials",
"client_id": "",
"client_secret": "",
"scope": "sellingpartnerapi::migration"
}
res = requests.post("https://api.amazon.com/auth/o2/token", params=params)
access_token = res.json()["access_token"]
print(f"access_token: {access_token}")
headers = {
"host": "sellingpartnerapi-na.amazon.com",
"x-amz-access-token": access_token.strip(),
"x-amz-date": datetime.now().strftime("%Y%m%dT%H%M%SZ"),
"user-agent": "App/1.0 (Language=Python)",
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
}
params = {
"sellingPartnerId": "",
"developerId": "",
"mwsAuthToken": ""
}
auth = AWS4Auth(ACCESS_ID, SECRET_ID, 'us-east-1', 'execute-api')
res = requests.get(TOKEN_URL, headers=headers, params=params, auth=auth)
print(res.headers)
print(res.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment