def testInappReceipts(): try: KEY_ID = 'XNUND9P95H' #ISSUER_ID = INAPP_ISSUER_ID #KEY_ID = '837666KJ65' ISSUER_ID = '32a99ecc-3f8d-482f-9b72-0abc088a6a7e' START_TIME = int(round(time.time()) ) # 20 minutes timestamp EXPIRATION_TIME = int(round(time.time() + (20.0 * 60.0))) # 20 minutes timestamp print("START_TIME ---> " , START_TIME) print("type of START_TIME ---> ", type(START_TIME)) PATH_TO_KEY = './SubscriptionKey_XNUND9P95H.p8' #PATH_TO_KEY = './appStoreConnect_apikey.p8' with open(PATH_TO_KEY, 'rb') as f: PRIVATE_KEY = f.read() header = { "alg": "ES256", "kid": KEY_ID, "typ": "JWT" } payload = { "iss": ISSUER_ID, "iat": START_TIME, "exp": EXPIRATION_TIME, "aud": "appstoreconnect-v1" } # options={ # 'verify_exp': False, # Skipping expiration date check # 'verify_aud': False # } # Create the JWT token = jwt.encode( payload, PRIVATE_KEY ,headers=header ) print("token is " , token) print("PRIVATE_KEY" ,PRIVATE_KEY ) # token = jwt.encode(header, payload, PRIVATE_KEY, options=options) original_transaction_id = '2000000281000188' # API Request #JWT = 'Bearer ' + token.decode() JWT = 'Bearer ' + token print("JWT ---> " , JWT) #URL = f'https://api.storekit-sandbox.itunes.apple.com/inApps/v1/history/{original_transaction_id}' URL = f'https://api.appstoreconnect.apple.com/v1/users/' HEAD = {'Authorization': JWT} print("URL--> ", URL) print("hEAD--> ", HEAD) r = requests.get(URL, params={'limit': 200}, headers=HEAD) print("r--->" , r) #print("output from test --> " , json.dumps(r.json()) ) # Write the response in a pretty printed JSON file with open('output.json', 'w') as out: out.write(json.dumps(r.json(), indent=4)) response = dict(status="success", message="Succeed") logger.info("Succeed") return response, HTTPStatus.BAD_REQUEST except: logger.exception("Failed") response = dict(status="fail", message="Failed") return response, HTTPStatus.BAD_REQUEST