I’ve been using this code to get automate download units every day for couple months but it’s not working since 22 Dec 2024 until now.
It turns out Failed to retrieve sales report - status code 403
with open(private_key_path, 'r') as key_file:
private_key = key_file.read()
current_time = int(time.time())
payload = {
'iss': issuer_id,
'exp': current_time + 60 * 10, # Token valid for 10 minutes
'aud': 'appstoreconnect-v1'
}
headers = {
'alg': 'ES256',
'kid': key_id,
'typ': 'JWT'
}
token = jwt.encode(payload, private_key, algorithm='ES256', headers=headers)
print(f"Generated JWT Token: {token}")
return token
# API Request setup
url = "https://api.appstoreconnect.apple.com/v1/salesReports"
headers = {"Authorization": f"Bearer {token}"}
params = {
"filter[reportType]": "SALES",
"filter[reportSubType]": "SUMMARY",
"filter[vendorNumber]": VENDOR_NUMBER,
"filter[frequency]": "DAILY",
"filter[reportDate]": report_date
}
try:
response = requests.get(url, headers=headers, params=params, timeout=120)
print(f"Response Status Code: {response.status_code}")
if response.status_code == 200:
# Parse and collect rows
try:
with gzip.open(BytesIO(response.content), 'rt') as gz:
reader = csv.DictReader(gz, delimiter='\t')
rows = list(reader)
print(f"Parsed {len(rows)} rows for {report_date}.")
except Exception as parse_error:
print(f"Error parsing data for {report_date}: {str(parse_error)}")
else:
print(f"Failed to retrieve sales report for {report_date} - Status code: {response.status_code}")
except requests.exceptions.RequestException as request_error:
print(f"Request failed for {report_date}: {str(request_error)}")
Hope there's any advices to help me get through this,
Thank you in advance