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)

DEĞERLİ: tommygod size vereceğim kodu kullanabilirsiniz

if response.status_code == 200: try: # Yanıtın içeriğini gziple çözme buffer = io.BytesIO(response.content) with gzip.GzipFile(fileobj=buffer) as f: content = f.read().decode('utf-8')

    # İçeriği DataFrame'e dönüştürme
    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'İşlem başarısız oldu. Hata: {e}'])

else: return pd.DataFrame(columns=['Error'], data=[f'Beklenmeyen durum kodu alındı {response.status_code}: {response.text}'])

apple turkiye gelişdirici fırat averbek saygılarımla

import requests, time, json from authlib.jose import jwt

EXPIRATION_TIME = int(round(time.time() + (10.0 * 60.0))) # 20 minutes timestamp PATH_TO_KEY = "AuthKey_KEY_ID.p8" with open(PATH_TO_KEY, "r") as f: PRIVATE_KEY = f.read() header = {"alg": "ES256", "kid": KEY_ID, "typ": "JWT"}

payload = { "iss": ISSUER_ID, "exp": EXPIRATION_TIME, "aud": "appstoreconnect-v1", "scope": ["GET /v1/salesReports"] }

Create the JWT

token = jwt.encode(header, payload, PRIVATE_KEY) print(token)

API Request

JWT = "Bearer " + token.decode() URL = "https://api.appstoreconnect.apple.com/v1/salesReports" HEAD = {"Authorization": JWT}

params = { "filter[frequency]": "DAILY", "filter[reportDate]": "2023-09-01", "filter[reportSubType]": "DETAILED", "filter[vendorNumber]": "vendor_number", "filter[reportType]": "SUBSCRIBER", "filter[version]": "1_3" }

r = requests.get(URL, params=params, headers=HEAD) print(r)

hi @Appleturkiye @tommygod I am using this snippet to download sales reports, but I am receiving a status 401 error. Is there a mistake I made when trying to download the report? Any suggestions would be helpful.

I need the Python code for connecting to my Apple appstore sales reports
 
 
Q