Countries
Read onlyHello, I am a seller from Korea and I want to use Amazon's API. I tried to receive a list through Python, but I encountered the error 'HTTP error occurred: 400 Client Error:', and I'm having trouble calling the API. How can I resolve this issue? Below is the Python code that I am trying to use.
import requests
import pandas as pd
from datetime import datetime, timezone
client_id =
client_secret =
refresh_token =
marketplace_id = 'ATVPDKIKX0DER'
def get_access_token():
url = 'https://api.amazon.com/auth/o2/token'
payload = {
'grant_type': 'refresh_token',
'refresh_token': refresh_token,
'client_id': client_id,
'client_secret': client_secret
}
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
response = requests.post(url, data=payload, headers=headers)
response.raise_for_status()
return response.json()['access_token']
def get_categories(access_token):
url = 'https://sellingpartnerapi-na.amazon.com/definitions/2020-09-01/productTypes'
headers = {
'Authorization': f'Bearer {access_token}',
'x-amz-access-token': access_token,
'x-amz-date': datetime.now(timezone.utc).strftime('%Y%m%dT%H%M%SZ'),
'x-amz-marketplace-id': marketplace_id,
'Content-Type': 'application/json'
}
response = requests.get(url, headers=headers)
response.raise_for_status()
return response.json()
def save_categories_to_excel(categories, filename):
category_list = []
for category_name, category_info in categories.get('productTypes', {}).items():
category_list.append({
'Category Name': category_name,
'Requirements': ', '.join(category_info.get('requirements', {}).get('attributes', []))
})
df = pd.DataFrame(category_list)
df.to_excel(filename, index=False)
print(f"Categories saved to {filename}")
if __name__ == '__main__':
try:
access_token = get_access_token()
categories = get_categories(access_token)
save_categories_to_excel(categories, 'amazon_categories.xlsx')
except requests.exceptions.HTTPError as err:
print(f"HTTP error occurred: {err}")
except Exception as e:
print(f"Error: {e}")
error massage : 'HTTP error occurred: 403 Client Error: for url: https://sellingpartnerapi-na.amazon.com/definitions/2020-09-01/productTypes'
Hi @taxonomy,
Thanks for the post. All sellers can download the Category Listings Report. Professional selling accounts already have access while individual sellers will need to request access from Selling Partner Support.
To generate a Category Listings Report, follow these steps:
Navigate to the Seller Central menu, and click Reports.
From the dropdown menu, select Category Listing Reports.
Select the other optional dropdowns to filter the data.
Click Download to initiate the report download process.
Best regards,
Rose_Amazon