I would like to get the daily number of units using python and Apple store connect API
So, I wrote the code referring to the document about Apple store connect API.
However, the execution result is returned as None.
The authority of the issued API key is sales and report
I'm afraid my English not so good
If the explanation is insufficient, please let me know as I will provide additional information.
python 3.8.4
Due to the effect of commenting out, the color coding is strange.
Result
So, I wrote the code referring to the document about Apple store connect API.
However, the execution result is returned as None.
The authority of the issued API key is sales and report
I'm afraid my English not so good
If the explanation is insufficient, please let me know as I will provide additional information.
Execution Environment
Windows 10python 3.8.4
Due to the effect of commenting out, the color coding is strange.
Code Block python import json import jwt import time import requests from datetime import datetime, timedelta # Signature method is fixed at ES256 ALGORITHM = 'ES256' # Please list your own key APP_STORE_KEY_ID = 'XXXXXXX' ISSUER_ID = 'XXXXXXX-XXXXXXX' STORE_AUTH_KEY = 'XXXXXXX.p8' secret = "" with open(STORE_AUTH_KEY,'r') as f: secret = f.read() # Apple's stipulated token expiration date is 20 minutes exp = int(time.mktime((datetime.now() + timedelta(minutes=20)).timetuple())) token = jwt.encode( { 'iss': ISSUER_ID, "exp": exp, "aud": "appstoreconnect-v1" # aud is fixed at appstoreconnect-v1 }, secret, algorithm=ALGORITHM, headers={ 'alg': ALGORITHM, 'kid': APP_STORE_KEY_ID, "typ": "JWT" } ) url = 'https://api.appstoreconnect.apple.com/v1/salesReports?filter[vendorNumber]=My_vendorNumber&filter[reportType]=SALES&filter[reportSubType]=SUMMARY&filter[frequency]=DAILY&filter[reportDate]=2021-03-01&filter[version]=1_0' hed = {'Authorization': 'Bearer {}'.format(token.decode('ascii'))} data = {} response = requests.get(url, headers=hed) # data = response.json() print(response.status_code) response = response.apparent_encoding # I got a json conversion error, so I added this line print(response) # print(json.dumps(data, ensure_ascii=False, indent=4))
Result
Code Block text $ python get_unit.py 200 None
I will supplement it because there was something that was not enough in the verification content
The sales summary report can be obtained from the screen below, but it has been confirmed that the downloaded CSV contains data.
https://appstoreconnect.apple.com/trends/reports
Also, even if I changed the reportSubType passed as a parameter to something else, the result returned was the same.
https://developer.apple.com/documentation/appstoreconnectapi/download_sales_and_trends_reports
Content-Type: gzip
Due to the above, apparent_encoding may not be working well, so let's check it out.
The sales summary report can be obtained from the screen below, but it has been confirmed that the downloaded CSV contains data.
https://appstoreconnect.apple.com/trends/reports
Also, even if I changed the reportSubType passed as a parameter to something else, the result returned was the same.
https://developer.apple.com/documentation/appstoreconnectapi/download_sales_and_trends_reports
Content-Type: gzip
Due to the above, apparent_encoding may not be working well, so let's check it out.