App store connect API returns 401

Hello, following the practices use on: https://developer.apple.com/documentation/appstoreconnectapi/generating_tokens_for_api_requests

I used Python, and uses pyjwt and request library in attempt of making requests

I created my jwt header and payload like this

jwt_header = {
  "alg": "ES256",
  "kid": MY_KEY_ID,
  "typ": "JWT"
}

jwt_payload = {
  "iss": MY_ISSUER_NUMBER,
  "iat": time_now,
  "exp": time_10_min,
  "aud": "appstoreconnect-v1"
}

and jwt can encode successfully without error

jwt_token = jwt.encode(jwt_payload, MY_SECRET_KEY, algorithm="ES256", headers= jwt_header)

but really when I try to make a get request with


get_app_id_endpoint = "https://api.appstoreconnect.apple.com/v1/apps"

headers = {
  'Authorization': f'Bearer {jwt_token}',
  'Content-Type': 'application/json'
}

response = requests.get(get_app_id_endpoint, headers=headers)

it always gets a 401 response. Is there anything that need to be changed here? I have tried sosme of the solutions found online such as

  1. take out "alg" field in jwt_header
  2. take out "iat" field in jwt_payload
  3. cast time_now and time_10_min (UNIX epoch time) to integer
  4. take out Content-Type filed in headers

but issue remains, what could I possible do here to get over it?

bump

Did your issue resolve?

I am also getting same issue

We're getting this too. Really wishing the documentation had more extensive examples or more info on how requests can fail

My tests have been failing for the past week and a half. Apple broke something

I also still getting the same error from sandbox "x": "Invalid response: Client error: GET https://api.storekit-sandbox.itunes.apple.com/inApps/v1/transactions/2000000632845273 resulted in a 401 Unauthorized response",

while for production url "x": "Invalid response: Client error: GET https://api.storekit.itunes.apple.com/inApps/v1/transactions/2000000632845273 resulted in a 404 Not Found response:\n{"errorCode":4040010,"errorMessage":"Transaction id not found."}\n",

App store connect API returns 401
 
 
Q