AutoIt
AutoIt
Zoom API - Create JWT to Authenticate API Requests
See more Zoom Examples
Creates a JWT for the Zoom API.Chilkat AutoIt Downloads
Local $bSuccess = False
; 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 $sApiKey = "o9rw6Gq0RnqlkfaSqtCMOA"
Local $sApiSecret = "UslmE23Kjh7at9z3If1xAHEyLmPDNxvxQrjR"
; Create a JWT to authenticate Zoom API requests.
$oJwt = ObjCreate("Chilkat.Jwt")
$oJose = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oJose.UpdateString("alg","HS256")
$bSuccess = $oJose.UpdateString("typ","JWT")
; Build claims to look like this:
; {"aud":null,"iss":"o9rw6Gq0RnqlkfaSqtCMOA","exp":1627651762,"iat":1627646363}
$oClaims = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oClaims.UpdateString("iss",$sApiKey)
$bSuccess = $oClaims.UpdateNull("aud")
; Set the timestamp of when the JWT was created to now.
Local $iCurDateTime = $oJwt.GenNumericDate(0)
$bSuccess = $oClaims.AddIntAt(-1,"iat",$iCurDateTime)
; Set the timestamp defining an expiration time (end time) for the token
; to be now + 1 month(3600 * 24 * 30 seconds)
Local $iOneMonth = 3600 * 24 * 30
$bSuccess = $oClaims.AddIntAt(-1,"exp",$iCurDateTime + $iOneMonth)
; Produce the smallest possible JWT:
$oJwt.AutoCompact = True
Local $strJwt = $oJwt.CreateJwt($oJose.Emit(),$oClaims.Emit(),$sApiSecret)
ConsoleWrite($strJwt & @CRLF)
; 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 = ObjCreate("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 = $strJwt
$oSbResponseBody = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oHttp.QuickGetSb("https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1",$oSbResponseBody)
If ($bSuccess = False) Then
ConsoleWrite($oHttp.LastErrorText & @CRLF)
Exit
EndIf
$oJResp = ObjCreate("Chilkat.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
$oJResp.EmitCompact = False
ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJResp.Emit() & @CRLF)
Local $iRespStatusCode = $oHttp.LastStatus
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
ConsoleWrite("Response Header:" & @CRLF)
ConsoleWrite($oHttp.LastHeader & @CRLF)
ConsoleWrite("Failed." & @CRLF)
Exit
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
Local $sId
Local $sFirst_name
Local $sLast_name
Local $sEmail
Local $iV_type
Local $iPmi
Local $sTimezone
Local $iVerified
Local $sCreated_at
Local $sLast_login_time
Local $sLanguage
Local $sPhone_number
Local $status
Local $sRole_id
Local $iPage_count = $oJResp.IntOf("page_count")
Local $iPage_number = $oJResp.IntOf("page_number")
Local $iPage_size = $oJResp.IntOf("page_size")
Local $iTotal_records = $oJResp.IntOf("total_records")
Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("users")
While $i < $iCount_i
$oJResp.I = $i
$sId = $oJResp.StringOf("users[i].id")
$sFirst_name = $oJResp.StringOf("users[i].first_name")
$sLast_name = $oJResp.StringOf("users[i].last_name")
$sEmail = $oJResp.StringOf("users[i].email")
$iV_type = $oJResp.IntOf("users[i].type")
$iPmi = $oJResp.IntOf("users[i].pmi")
$sTimezone = $oJResp.StringOf("users[i].timezone")
$iVerified = $oJResp.IntOf("users[i].verified")
$sCreated_at = $oJResp.StringOf("users[i].created_at")
$sLast_login_time = $oJResp.StringOf("users[i].last_login_time")
$sLanguage = $oJResp.StringOf("users[i].language")
$sPhone_number = $oJResp.StringOf("users[i].phone_number")
$status = $oJResp.StringOf("users[i].status")
$sRole_id = $oJResp.StringOf("users[i].role_id")
$i = $i + 1
Wend