Using the App Store Connect API

Generating a Team API Key

  • To generate a team API key to use with the App Store Connect API, log in to App Store Connect and:
  • Select Users and Access, and then select the “Integrations” tab.
  • Select “Team Keys” or “Individual Keys” based on your needs.
  • Click the Generate API Key or the Add (+) button.
  • Enter a name for the key. The name is for your reference only and isn’t part of the key itself.
  • Under Access, select the role for the key.
  • Click Generate.
  • The new key’s name, key ID, download link, and other information appear on the page.

Generating a JSON Web Token (JWT) for a Team API Key using Python

import datetime

from authlib.jose import jwt

def main():
    header = {
        'alg': 'ES256',
        'kid': 'ENTER YOUR KID HERE',
        'typ': 'JWT'
    }

    payload = {
        'iss': 'ENTER YOUR ISS HERE',
        'aud': 'appstoreconnect-v1',
        'exp': int(datetime.datetime.now().timestamp()) + 1200 
    }
    # The generated token is valid for 20 minutes.For more information on geneating JWT see docs here https://developer.apple.com/go/?id=api-generating-tokens

    key = open('AuthKey_XXXXXXXXXX.p8', 'r').read()
    token = jwt.encode(header, payload, key).decode('utf-8')

    print(token)

if __name__ == '__main__':
    main()

Generating a JSON Web Token (JWT) for an Individual API Key using Python

import datetime

from authlib.jose import jwt

def main():
    header = {
        'alg': 'ES256',
        'kid': 'ENTER YOUR KID HERE', 
        'typ': 'JWT'
    }

    payload = {
        # Individual keys don’t use the Issuer ID key iss, but do require the Subject key sub.
        # Only required for individual keys
        'sub': 'user', 

        'aud': 'appstoreconnect-v1',
        'exp': int(datetime.datetime.now().timestamp()) + 1200 
    }
    # The generated token is valid for 20 minutes.For more information on geneating JWT see docs here https://developer.apple.com/go/?id=api-generating-tokens

    key = open('ApiKey_XXXXXXXXXXXX.p8', 'r').read()
    token = jwt.encode(header, payload, key).decode('utf-8')

    print(token)

if __name__ == '__main__':
    main()

Making your first App Store Connect API request

  • Generate a JSON Web Token using one of the Python scripts from above for a Team API Key or Individual API Key.
  • Use Postman or Curl to test the following GET request:
GET https://api.appstoreconnect.apple.com/v1/apps

Bearer Token: [Token generated from Python script]
  • If the request was successful you should get a response listing all your apps from App Store Connect:
{
  "data": []
}

Resources

Leave a comment