Sample code for 30+ languages & platforms
Lua

Zoom API - Create JWT to Authenticate API Requests

See more Zoom Examples

Creates a JWT for the Zoom API.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.

-- Use your API key and secret here...
local apiKey = "o9rw6Gq0RnqlkfaSqtCMOA"
local apiSecret = "UslmE23Kjh7at9z3If1xAHEyLmPDNxvxQrjR"

-- Create a JWT to authenticate Zoom API requests.
local jwt = chilkat.Jwt.new()

local jose = chilkat.JsonObject.new()
local success = jose:update_string("alg", "HS256")
success = jose:update_string("typ", "JWT")

-- Build claims to look like this:
-- {"aud":null,"iss":"o9rw6Gq0RnqlkfaSqtCMOA","exp":1627651762,"iat":1627646363}
local claims = chilkat.JsonObject.new()
success = claims:update_string("iss", apiKey)
success = claims:update_null("aud")

-- Set the timestamp of when the JWT was created to now.
local curDateTime = jwt:gen_numeric_date(0)
success = claims:add_int_at(-1, "iat", curDateTime)

-- Set the timestamp defining an expiration time (end time) for the token
-- to be now + 1 month(3600 * 24 * 30 seconds)
local oneMonth = 3600 * 24 * 30
success = claims:add_int_at(-1, "exp", curDateTime + oneMonth)

-- Produce the smallest possible JWT:
jwt.auto_compact = true

local strJwt = jwt:create_jwt(jose:emit(), claims:emit(), apiSecret)

print(strJwt)

-- Let's test the JWT to by sending the following request:

-- curl --request GET \
--   --url 'https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1' \
--   --header 'authorization: Bearer { your_token }' \
--   --header 'content-type: application/json

local http = chilkat.Http.new()

-- Implements the following CURL command:

-- curl --request GET \
--   --url 'https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1' \
--   --header 'authorization: Bearer { your_token }' \
--   --header 'content-type: application/json

-- Use the following online tool to generate HTTP code from a CURL command
-- Convert a cURL Command to HTTP Source Code

http:set_request_header("content-type", "application/json")
-- Adds the "Authorization: Bearer { your_token }" header.
http.auth_token = strJwt

local sbResponseBody = chilkat.StringBuilder.new()
success = http:quick_get_sb("https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1", sbResponseBody)
if not success then
    print(http.last_error_text)
    return
end

local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false

print("Response Body:")
print(jResp:emit())

local respStatusCode = http.last_status
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
    print("Response Header:")
    print(http.last_header)
    print("Failed.")
    return
end

-- Sample output:

-- {
--   "page_count": 1,
--   "page_number": 1,
--   "page_size": 30,
--   "total_records": 1,
--   "users": [
--     {
--       "id": "s8uAiMJiRmS_-eu1yOhKlg",
--       "first_name": "Joe",
--       "last_name": "Example",
--       "email": "joe@example.com",
--       "type": 1,
--       "pmi": 5224934114,
--       "timezone": "America/Chicago",
--       "verified": 1,
--       "created_at": "2021-07-30T11:56:37Z",
--       "last_login_time": "2021-07-30T11:56:37Z",
--       "language": "en-US",
--       "phone_number": "",
--       "status": "active",
--       "role_id": "0"
--     }
--   ]
-- }

-- Sample code for parsing the JSON response...
-- Use the following online tool to generate parsing code from sample JSON:
-- Generate Parsing Code from JSON

local id = ""
local first_name = ""
local last_name = ""
local email = ""
local v_type = 0
local pmi = 0
local timezone = ""
local verified = 0
local created_at = ""
local last_login_time = ""
local language = ""
local phone_number = ""
local status = ""
local role_id = ""

local page_count = jResp:int_of("page_count")
local page_number = jResp:int_of("page_number")
local page_size = jResp:int_of("page_size")
local total_records = jResp:int_of("total_records")
local i = 0
local count_i = jResp:size_of_array("users")
while i < count_i do
    jResp.i = i
    id = jResp:string_of("users[i].id")
    first_name = jResp:string_of("users[i].first_name")
    last_name = jResp:string_of("users[i].last_name")
    email = jResp:string_of("users[i].email")
    v_type = jResp:int_of("users[i].type")
    pmi = jResp:int_of("users[i].pmi")
    timezone = jResp:string_of("users[i].timezone")
    verified = jResp:int_of("users[i].verified")
    created_at = jResp:string_of("users[i].created_at")
    last_login_time = jResp:string_of("users[i].last_login_time")
    language = jResp:string_of("users[i].language")
    phone_number = jResp:string_of("users[i].phone_number")
    status = jResp:string_of("users[i].status")
    role_id = jResp:string_of("users[i].role_id")
    i = i + 1
end