Created
April 27, 2021 12:57
-
-
Save louis030195/269f7ba8525d889efa98f109460e4884 to your computer and use it in GitHub Desktop.
Apple App Store Connect API in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
Author
louis030195
commented
Apr 27, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment