In this article, I will show you the way to get Units, the term indicates how many downloads on your own application published on App Store, following by days, months, years, using Python script


Make sure you have your own privileges to access App Store Connect and generate below information

Generate API Key, download Private Key,

- Select Users and Access, and then select the API Keys tab.
- Click Generate API Key or the Add (+) button.
- Enter a name for the key. The name is for your reference only and is not part of the key itself.
- Under Access, select the role for the key.
- Click Generate.
- Click "Download API Key" link next to the new API key.
More instruction: https://developer.apple.com/documentation/appstoreconnectapi/creating_api_keys_for_app_store_connect_api

The API Key looks like this format

2X9R4HXF34

The Private Key looks like this format

---- Begin Private Key ----
Key....
---- End Private Key ----

Also from Connector page, please prepares more 2 Ids to process next step

IssuerId. Ex: 57246542-96fe-1a63-e053-0824d011072a
VendorId. Ex. 1234567
More Instruction: https://help.apple.com/app-store-connect/#/dev3a16f3fe0

So, in total, make sure you already kept:

IssuerId
VendorId
KeyId = API Key
PrivateKey

Sign JWT Token

Next, we will use them to create and sign JWT Token, I have created a python function to archieve downloading, if you are using another language or simply RESTful, please follow official instruction here
https://developer.apple.com/documentation/appstoreconnectapi/generating_tokens_for_api_requests

# pip install pyjwt
# pip install pyjwt[crypto]
from datetime import datetime, timezone
import jwt

def sign_appstore_token(issuer_id, key_id, generated_private_key):
    bin_private_key = generated_private_key.encode()
    current_unix = int(datetime.now(tz=timezone.utc).timestamp())
    token = jwt.encode({
            "iss": issuer_id,
            "iat": current_unix,
            "exp": current_unix + 1000, 
            "aud": "appstoreconnect-v1",
    }, key= bin_private_key, algorithm= 'ES256', headers= {
        "alg": "ES256",
        "kid": key_id,
        "typ": "JWT"
    })
    return token

Download report

This link provides the method to download report https://developer.apple.com/documentation/appstoreconnectapi/download_sales_and_trends_reports

Be noticed that to get the Units, reportType should be SALES. Also noticed that reportDate and frequency have to consistency each other, if you specify:

  • filter[frequency] = YEARLY, then filter[reportDate] = 2021
  • filter[frequency] = MONTHLY, then filter[reportDate] = 2021-06.
    The frequency configuration groups the report to a file, depends on your needs.

Sample query:

https://api.appstoreconnect.apple.com/v1/salesReports?filter[frequency]=YEARLY&filter[reportDate]=2021&filter[reportSubType]=SUMMARY&filter[reportType]=SALES&filter[vendorNumber]=YOUR_VENDOR_ID
Headers: Authorization: Bearer YOUR_ABOVE_TOKEN

You will get binary response if it is success, represented for .gz file as well. Extract gz to get .txt schema deliminated by \t

Python script here returns file content as text, you can do your next step, pandas table, or to model, it is up to you

import requests
import gzip
def download_appstore_objects(token, vendor_id, frequency, reportDate):
    link = f'https://api.appstoreconnect.apple.com/v1/salesReports?filter[frequency]={frequency}&filter[reportDate]={reportDate}&filter[reportSubType]=SUMMARY&filter[reportType]=SALES&filter[vendorNumber]={vendor_id}'
    response = requests.get(link, headers= {'Authorization': f'Bearer {token}' })
    file_content = gzip.decompress(response.content).decode('utf-8')
    return file_content

Columns included:

Provider    
Provider Country    
SKU Developer   
Title   
Version 
Product Type Identifier 
Units   
Developer Proceeds  
Begin Date  
End Date    
Customer Currency   
Country Code    
Currency of Proceeds    
Apple Identifier    
Customer Price  
Promo Code  
Parent Identifier   
Subscription    
Period  Category    
CMB 
Device  
Supported Platforms
Proceeds Reason 
Preserved Pricing   
Client  
Order 
Type

About field types, please refer https://help.apple.com/app-store-connect/#/dev15f9508ca


Previous Post:
Next Post:
0%