Sometime back Apple had opened up the AppStore Connect API for its developers. The API is a bunch of RESTful service which can be used to customise and automate our workflows. It helps us automate tasks across developer tools, such as App Store Connect, Xcode, and Certificates, Identifiers & Profiles, to give us greater flexibility and increased efficiency in our workflows. We could use it for development, beta testing, managing app metadata, reporting etc.
It can be very helpful to invoke the AppStore Connect API via command line. I use it primarily to check the structure of the response object. Although the documentation of the AppStore Connect API is good, but there is nothing as good as seeing the response object with real values in it.
In this post we will see how can we invoke the AppStore Connect API from the command line.
How To Do It?
To invoke the AppStore Connect API via command line we will follow these steps.
- Create API Key from the App Store Connect Web Portal
- Create JWT JSON Token for Accessing API using XCToken
- Invoking the API from command line using curl.
Create API Key
- To generate an API Key you will need to login to iTunes Connect portal.
- Navigate to the "Users and Access" section
- In there, navigate to the "Keys" tab
- Choose the "Key Type" as "AppStore Connect API"
- Make a note of the "Issuer Id" we will be using this later on to generate the JWT JSON Token.
- Generate a New API Key, by clicking the "+" icon. This will open up a dialog which ask you to name the key and select the Access type. I am going to choose "Developer" for this post.
- This will generate the API key, make a note of the generated Key Id we will be using it later to generated the JWT JSON Token.
- iTunesConnect will give you an opportunity to download the generated key only once. So please make sure you download it and keep it safe.
- This completes the steps necessary to generate an API Key.
Create JWT JSON Token
gem install xctoken
- ISSUER_ID = This is the issuer id which we have noted in the earlier step from the iTunes Connect page.
- KEY_DIR = The full directory path where the API key was downloaded from iTunes Connect
- KEY_ID = The key id of the newly generated API key.
export ISSUER_ID=ABCD
export KEY_DIR=~/Downloads/
export KEY_ID=ABCD1234
xctoken generate
Invoking the API
curl https://api.appstoreconnect.apple.com/v1/apps --Header "Authorization: Bearer <GENERATED TOKEN>"