Xbase++
Xbase++
Zoom API - Create JWT to Authenticate API Requests
See more Zoom Examples
Creates a JWT for the Zoom API.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL cApiKey
LOCAL cApiSecret
LOCAL oJwt
LOCAL oJose
LOCAL oClaims
LOCAL nCurDateTime
LOCAL nOneMonth
LOCAL cStrJwt
LOCAL oHttp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nRespStatusCode
LOCAL cId
LOCAL cFirst_name
LOCAL cLast_name
LOCAL cEmail
LOCAL nV_type
LOCAL nPmi
LOCAL cTimezone
LOCAL nVerified
LOCAL cCreated_at
LOCAL cLast_login_time
LOCAL cLanguage
LOCAL cPhone_number
LOCAL cStatus
LOCAL cRole_id
LOCAL nPage_count
LOCAL nPage_number
LOCAL nPage_size
LOCAL nTotal_records
LOCAL i
LOCAL nCount_i
nSuccess := 0
// 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...
cApiKey := "o9rw6Gq0RnqlkfaSqtCMOA"
cApiSecret := "UslmE23Kjh7at9z3If1xAHEyLmPDNxvxQrjR"
// Create a JWT to authenticate Zoom API requests.
oJwt := CreateObject("Chilkat.Jwt")
oJose := CreateObject("Chilkat.JsonObject")
nSuccess := oJose:UpdateString("alg", "HS256")
nSuccess := oJose:UpdateString("typ", "JWT")
// Build claims to look like this:
// {"aud":null,"iss":"o9rw6Gq0RnqlkfaSqtCMOA","exp":1627651762,"iat":1627646363}
oClaims := CreateObject("Chilkat.JsonObject")
nSuccess := oClaims:UpdateString("iss", cApiKey)
nSuccess := oClaims:UpdateNull("aud")
// Set the timestamp of when the JWT was created to now.
nCurDateTime := oJwt:GenNumericDate(0)
nSuccess := oClaims:AddIntAt(-1, "iat", nCurDateTime)
// Set the timestamp defining an expiration time (end time) for the token
// to be now + 1 month(3600 * 24 * 30 seconds)
nOneMonth := 3600 * 24 * 30
nSuccess := oClaims:AddIntAt(-1, "exp", nCurDateTime + nOneMonth)
// Produce the smallest possible JWT:
oJwt:AutoCompact := 1
cStrJwt := oJwt:CreateJwt(oJose:Emit(), oClaims:Emit(), cApiSecret)
? cStrJwt
// 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
oHttp := CreateObject("Chilkat.Http")
// 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
oHttp:SetRequestHeader("content-type", "application/json")
// Adds the "Authorization: Bearer { your_token }" header.
oHttp:AuthToken := cStrJwt
oSbResponseBody := CreateObject("Chilkat.StringBuilder")
nSuccess := oHttp:QuickGetSb("https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1", oSbResponseBody)
IF (nSuccess == 0)
? oHttp:LastErrorText
oJwt:destroy()
oJose:destroy()
oClaims:destroy()
oHttp:destroy()
oSbResponseBody:destroy()
RETURN
ENDIF
oJResp := CreateObject("Chilkat.JsonObject")
oJResp:LoadSb(oSbResponseBody)
oJResp:EmitCompact := 0
? "Response Body:"
? oJResp:Emit()
nRespStatusCode := oHttp:LastStatus
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode >= 400)
? "Response Header:"
? oHttp:LastHeader
? "Failed."
oJwt:destroy()
oJose:destroy()
oClaims:destroy()
oHttp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()
RETURN
ENDIF
// 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
nPage_count := oJResp:IntOf("page_count")
nPage_number := oJResp:IntOf("page_number")
nPage_size := oJResp:IntOf("page_size")
nTotal_records := oJResp:IntOf("total_records")
i := 0
nCount_i := oJResp:SizeOfArray("users")
DO WHILE i < nCount_i
oJResp:I := i
cId := oJResp:StringOf("users[i].id")
cFirst_name := oJResp:StringOf("users[i].first_name")
cLast_name := oJResp:StringOf("users[i].last_name")
cEmail := oJResp:StringOf("users[i].email")
nV_type := oJResp:IntOf("users[i].type")
nPmi := oJResp:IntOf("users[i].pmi")
cTimezone := oJResp:StringOf("users[i].timezone")
nVerified := oJResp:IntOf("users[i].verified")
cCreated_at := oJResp:StringOf("users[i].created_at")
cLast_login_time := oJResp:StringOf("users[i].last_login_time")
cLanguage := oJResp:StringOf("users[i].language")
cPhone_number := oJResp:StringOf("users[i].phone_number")
cStatus := oJResp:StringOf("users[i].status")
cRole_id := oJResp:StringOf("users[i].role_id")
i := i + 1
ENDDO
oJwt:destroy()
oJose:destroy()
oClaims:destroy()
oHttp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()