I need the python code for connecting to my apple app store sales reports

Hi 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 alot of techniques I tried. I'm probably missing some parameters or something. **Can someone give me the full code they use if they do something similar? **

Thanks ALOT


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)


Posted on Aug 14, 2023 10:46 AM

Reply

There are no replies.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

I need the python code for connecting to my apple app store sales reports

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.