Skip to content

Instantly share code, notes, and snippets.

@louis030195
Created April 27, 2021 12:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save louis030195/269f7ba8525d889efa98f109460e4884 to your computer and use it in GitHub Desktop.
Save louis030195/269f7ba8525d889efa98f109460e4884 to your computer and use it in GitHub Desktop.
Apple App Store Connect API in Python
import jwt
import requests
import time
# More details here
# https://developer.apple.com/documentation/appstoreconnectapi
def generate_token():
expiration_in_ten_minutes = int(time.time() + 600)
payload = {
"iss": "YOUR_ISSUER_ID",
"exp": expiration_in_ten_minutes,
"aud": "appstoreconnect-v1"
}
headers = {
"alg": "ES256",
"kid": "YOUR_KEY_ID",
"typ": "JWT"
}
f = open("YOUR_PRIVATE_KEY.p8", "r")
private_key = f.read()
token = jwt.encode(payload=payload, key=private_key, algorithm="ES256", headers=headers)
return token
# Examples
def delete_bundle_id(token: str, bundle_id: str):
r = requests.delete(f"https://api.appstoreconnect.apple.com/v1/bundleIds/{bundle_id}",
headers={"Authorization": f"Bearer {token}"})
print(r.status_code)
print(r.text)
def get_bundle_ids(token: str):
r = requests.get(f"https://api.appstoreconnect.apple.com/v1/bundleIds",
headers={"Authorization": f"Bearer {token}"})
print(r.status_code)
print(r.text)
@louis030195
Copy link
Author

pip install pyjwt requests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment