Post

Replies

Boosts

Views

Activity

I need the Python code for connecting to my Apple appstore sales reports
I am trying to create an API that connects to the apple app store, I already converted my p8 into a JWT, it works for other appstore information but not sales. Here is what I have so far, this is a mix of a lot of techniques I tried. Can someone give me the full code they use if they do something similar? import requests import json import zlib from io import StringIO Constants API_ENDPOINT = 'https://api.appstoreconnect.apple.com/v1/salesReports' Load JWT token from file with open("My location for my JWT file", "r") as file: token = file.read().strip() def get_sales_report(): headers = { 'Authorization': f'Bearer {token}', 'Content-Type': 'application/a-gzip' } params = { 'filter[frequency]': 'DAILY', # For testing purposes, using DAILY frequency 'filter[reportType]': 'SALES', 'filter[vendorNumber]': 'My vendor', 'filter[reportDate]': '2022-08-01' # Sample date for testing } response = requests.get(API_ENDPOINT, headers=headers, params=params) if response.status_code == 200: try: # Decompress the gzipped content buffer = io.BytesIO(response.content) with gzip.GzipFile(fileobj=buffer) as f: content = f.read().decode('utf-8') # Convert the content to a DataFrame data = [line.split('\t') for line in content.split('\n') if line] df = pd.DataFrame(data[1:], columns=data[0]) return df except Exception as e: return pd.DataFrame(columns=['Error'], data=[f'Failed to process the report. Error: {e}']) else: return pd.DataFrame(columns=['Error'], data=[f'Received unexpected status code {response.status_code}: {response.text}']) sales_df = get_sales_report() print(sales_df)
2
0
1.7k
Aug ’23