Article

Generating Tokens for API Requests

Create JSON Web Tokens signed with your private key to authorize API requests.

Overview

JSON Web Token (JWT) is an open standard (RFC 7519) that defines a way to securely transmit information. The App Store Connect API requires JWTs to authorize each API request. You create the token, signing it with the private key you downloaded from App Store Connect.

To generate a signed JWT:

  1. Create the JWT header.

  2. Create the JWT payload.

  3. Sign the JWT.

Include the signed JWT in the authorization header of each App Store Connect API request.

Create the JWT Header

To create a JWT to communicate with the App Store Connect API, use the following fields and values in the header:

Header Field

Value

alg - Encryption Algorithm

ES256

All JWTs for App Store Connect API must be signed with ES256 encryption

kid - Key Identifier

Your private key ID from App Store Connect (Ex: 2X9R4HXF34)

typ - Token Type

JWT

To get your key ID, copy it from App Store Connect by logging in to App Store Connect, then:

  1. Select Users and Access, then select the API Keys tab.

  2. The key IDs appear in a column under the Active heading. Hover the cursor next to a key ID to display the Copy Key ID link.

  3. Click Copy Key ID.

If you have more than one API key, use the key ID of the same private key that you use to sign the JWT.

Here's an example of a JWT header:

{
"alg": "ES256",
"kid": "2X9R4HXF34",
"typ": "JWT"
}

Create the JWT Payload

The JWT payload contains information specific to the App Store Connect APIs, such as issuer ID and expiration time. Use the following fields and values in the JWT payload:

Payload Field

Value

iss - Issuer ID

Your issuer ID from the API Keys page in App Store Connect (Ex: 57246542-96fe-1a63-e053-0824d011072a)

exp - Expiration Time

The token's expiration time, in Unix epoch time; tokens that expire more than 20 minutes in the future are not valid (Ex: 1528408800)

aud - Audience

appstoreconnect-v1

To get your issuer ID, log in to App Store Connect and:

  1. Select Users and Access, then Select the API Keys tab.

  2. The issuer ID appears near the top of the page. To copy the issuer ID, click Copy next to the ID.

Here's an example of a JWT payload:

{
"iss": "57246542-96fe-1a63-e053-0824d011072a",
"exp": 1528408800,
"aud": "appstoreconnect-v1"
}

Sign the JWT

Use the private key associated with the key ID you specified in the header to sign the token.

Regardless of the programming language you're using with the App Store Connect API, there are a variety of open source libraries available online for creating and signing JWT tokens. See JWT.io for more information.

Include the JWT in the Request's Authorization Header

Once you have a complete and signed token, provide the token in the request's authorization header as a bearer token.

The following example shows a curl command using a bearer token. Replace the text "[signed token]" with the value of the signed token itself.

curl -v -H 'Authorization: Bearer [signed token]' 
"https://api.appstoreconnect.apple.com/v1/apps"

See Also

First Steps

Creating API Keys for App Store Connect API

Create API keys used to sign JWTs and authorize API requests.

Revoking API Keys

Revoke unused, lost, or compromised private keys.