Python Forum
JWT and Apple Store Connect API
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
JWT and Apple Store Connect API
#1
Hello All

would welcome any advice on the following thank you

I am trying to use Apple's Connect API to download reports (sales etc.

the following code runs with out any error but I cant find an example of how to use the JWT

from datetime import datetime, timedelta
import jwt


KEY_ID = "mykey_id"
ISSUER_ID = "issuse_id_string"
PRIVATE_KEY = Auth key file on my pc.p8"

TIMESTAMP = int( (datetime.now() - timedelta(minutes = 45)).timestamp() * 1000)

claim = {"iss" : ISSUER_ID,
         "exp" : TIMESTAMP,
         "aud" : "appstoreconnect-v1"}

header = {
          "alg": "ES256",
          "kid": KEY_ID,
          "typ": "JWT"
         }

    # Create the JWT
jwttoken = jwt.encode(claim, PRIVATE_KEY, algorithm='ES256', headers=header)
Would anyone know where i can find a simple example on using "jwttoken"??


I have also tried using appstoreconnect as follows however I get a token error

from appstoreconnect import Api

KEY_ID = "mykey_id"
ISSUER_ID = "issuse_id_string"
PRIVATE_KEY = Auth key file on my pc.p8"

api = Api(KEY_ID, PRIVATE_KEY, ISSUER_ID)

print (api)
apps = api.list_apps()
for app in apps:
    print(app)
Error follows
<appstoreconnect.api.Api object at 0x00000275AC86EB00>
Traceback (most recent call last):
File "C:\src\Sandbox\python\test2.py", line 13, in <module>
for app in apps:
File "C:\Users\DevUser\AppData\Local\Programs\Python\Python36\lib\site-packages\appstoreconnect\api.py", line 79, in __next__
self.fetch_page()
File "C:\Users\DevUser\AppData\Local\Programs\Python\Python36\lib\site-packages\appstoreconnect\api.py", line 96, in fetch_page
self.payload = self.api._api_call(self.url)
File "C:\Users\DevUser\AppData\Local\Programs\Python\Python36\lib\site-packages\appstoreconnect\api.py", line 134, in _api_call
raise APIError(payload.get('errors', [])[0].get('detail', 'Unknown error'))
appstoreconnect.api.APIError: Provide a properly configured and signed bearer token, and make sure that it has not expired. Learn more about Generating Tokens for API Requests https://developer.apple.com/go/?id=api-g...ing-tokens
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Installing Miniforge for Apple m1 Processor Led_Zeppelin 2 5,729 Jun-25-2021, 08:45 PM
Last Post: snippsat
  accessing socket on Apple MAC georgelza 2 3,304 Nov-20-2017, 10:48 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020