I using the below to generate the token. but it returns 401 due to token life time > 20 minuts
import requests, time, json
from authlib.jose import jwt
KEY_ID = "key_id"
ISSUER_ID = "issuer_id"
EXPIRATION_TIME = int(round(time.time() + (30.0 * 60.0))) # 20 minutes timestamp
PATH_TO_KEY = "AuthKey_keyid.p8"
with open(PATH_TO_KEY, "r") as f:
PRIVATE_KEY = f.read()
header = {"alg": "ES256", "kid": KEY_ID, "typ": "JWT"}
payload = {
"iss": ISSUER_ID,
"exp": EXPIRATION_TIME,
"aud": "appstoreconnect-v1",
"scope": ["GET /v1/salesReports?filter[frequency]=DAILY&filter[reportDate]=2023-09-01&filter[reportSubType]=DETAILED&filter[vendorNumber]={vendor_number}&filter[reportType]=SUBSCRIBER&filter[version]=1_3"]
}
# Create the JWT
token = jwt.encode(header, payload, PRIVATE_KEY)
print(token)
# API Request
JWT = "Bearer " + token.decode()
URL = "https://api.appstoreconnect.apple.com/v1/salesReports"
HEAD = {"Authorization": JWT}
params = {
"filter[frequency]": "DAILY",
"filter[reportDate]": "2023-09-01",
"filter[reportSubType]": "DETAILED",
"filter[vendorNumber]": "vendor_number",
"filter[reportType]": "SUBSCRIBER",
"filter[version]": "1_3"
}
r = requests.get(URL, params=params, headers=HEAD)
print(r)
Do you have any suggestions to generate the token with 15 days life time