-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetItemIds.py
More file actions
165 lines (130 loc) · 5.26 KB
/
getItemIds.py
File metadata and controls
165 lines (130 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import requests
import json
import argparse
def fetch_apps(token):
"""
Fetch app names and IDs from App Store Connect API
Args:
token (str): App Store Connect API token
Returns:
list: List of dictionaries containing app information
"""
endpoint = "https://api.appstoreconnect.apple.com/v1/apps?fields[apps]=name,bundleId"
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
try:
response = requests.get(endpoint, headers=headers)
response.raise_for_status()
data = response.json()
apps = []
if 'data' in data:
for app in data['data']:
app_info = {
'id': app['id'],
'name': app['attributes']['name'] if 'attributes' in app and 'name' in app['attributes'] else 'Unknown',
'bundleId': app['attributes']['bundleId'] if 'attributes' in app and 'bundleId' in app['attributes'] else 'Unknown'
}
apps.append(app_info)
return apps
except requests.exceptions.RequestException as e:
print(f"Error fetching apps: {e}")
if hasattr(e, 'response') and e.response is not None:
print(f"Response: {e.response.text}")
return []
def fetch_apps_with_skus(token):
"""
Fetch all apps and their SKUs from App Store Connect API
Args:
token (str): App Store Connect API token
Returns:
list: List of dictionaries containing app information including SKU
"""
endpoint = "https://api.appstoreconnect.apple.com/v1/apps?fields[apps]=name,bundleId,sku&limit=200"
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
apps = []
try:
while endpoint:
response = requests.get(endpoint, headers=headers)
response.raise_for_status()
data = response.json()
if 'data' in data:
for app in data['data']:
attributes = app.get('attributes', {})
app_info = {
'id': app['id'],
'name': attributes.get('name', 'Unknown'),
'bundleId': attributes.get('bundleId', 'Unknown'),
'sku': attributes.get('sku', 'Unknown')
}
apps.append(app_info)
endpoint = data.get('links', {}).get('next')
return apps
except requests.exceptions.RequestException as e:
print(f"Error fetching apps with SKUs: {e}")
if hasattr(e, 'response') and e.response is not None:
print(f"Response: {e.response.text}")
return []
def fetch_in_app_purchases(token, app_id):
"""
Fetch in-app purchases for a specific app from App Store Connect API
Args:
token (str): App Store Connect API token
app_id (str): App ID to fetch in-app purchases for
Returns:
list: List of dictionaries containing in-app purchase information
"""
endpoint = f"https://api.appstoreconnect.apple.com/v1/apps/{app_id}/inAppPurchasesV2?limit=200"
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
try:
response = requests.get(endpoint, headers=headers)
response.raise_for_status()
data = response.json()
iaps = []
if 'data' in data:
for iap in data['data']:
iap_info = {
'id': iap['id'],
'name': iap['attributes']['name'] if 'attributes' in iap and 'name' in iap['attributes'] else 'Unknown',
'productId': iap['attributes']['productId'] if 'attributes' in iap and 'productId' in iap['attributes'] else 'Unknown'
}
iaps.append(iap_info)
return iaps
except requests.exceptions.RequestException as e:
print(f"Error fetching in-app purchases for app {app_id}: {e}")
if hasattr(e, 'response') and e.response is not None:
print(f"Response: {e.response.text}")
return []
def main():
parser = argparse.ArgumentParser(description='Fetch apps and in-app purchases from App Store Connect')
parser.add_argument('--token', required=True, help='App Store Connect API token')
parser.add_argument('--skus', action='store_true', help='Print all apps and their SKUs, then exit')
args = parser.parse_args()
if args.skus:
apps = fetch_apps_with_skus(args.token)
if apps:
for app in apps:
print(f"{app['name']},{app['sku']}")
else:
print("No apps found or error occurred.")
return
apps = fetch_apps(args.token)
if apps:
for app in apps:
print(f"{app['name']},{app['bundleId']},{app['id']}")
for app in apps:
iaps = fetch_in_app_purchases(args.token, app['id'])
if iaps:
for iap in iaps:
print(f"{iap['name']},{iap['productId']},{iap['id']},{app['name']}")
else:
print("No apps found or error occurred.")
if __name__ == "__main__":
main()