Always get "Invalid access token." using python and jwt

Description
The code is actually copied from zoom forum (Zoom JWT Token Creation - Automate the Process)

import jwt
import requests
import json
from time import time

API_KEY = ‘???’
API_SEC = ‘???’

#create a function to generate a token using the pyjwt library
def generateToken():
token = jwt.encode(
# Create a payload of the token containing API Key & expiration time
{“iss”: API_KEY, “exp”: time() + 5000},
# Secret used to generate token signature
API_SEC,
# Specify the hashing alg
algorithm=‘HS256’
# Convert token to utf-8
).decode(‘utf-8’)

return token

#send a request with headers including a token

def getUsers():
headers = {‘authorization’: ‘Bearer %s’ % generateToken(),
‘content-type’: ‘application/json’}

r = requests.get('https://api.zoom.us/v2/users/', headers=headers)

print(r.text)

Error
When I run it, I always get
{“code”:124,“message”:“Invalid access token.”}

Which App Type (OAuth / Chatbot / JWT / Webhook)?
JWT

How To Reproduce (If applicable)
Steps to reproduce the behavior:

  1. create an test.py, paste the code above, change key and sec,
    python3 test.py
  2. See error

I find the issue. I have to create a JWT app. Then use the key and secret generate for JWT app.
The previous one is a SDK app, that’s why it’s key and secret doesn’t work

Hey @TomJerry, glad you were able to figure this out! :100:

Best,
Will

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.