Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) Zoom API - Create JWT to Authenticate API RequestsSee more Zoom ExamplesCreates a JWT for the Zoom API. For more information, see https://marketplace.zoom.us/docs/api-reference/using-zoom-apis#using-jwt
integer li_rc string ls_ApiKey string ls_ApiSecret oleobject loo_Jwt oleobject loo_Jose integer li_Success oleobject loo_Claims integer li_CurDateTime integer li_OneMonth string ls_StrJwt oleobject loo_Http oleobject loo_SbResponseBody oleobject loo_JResp integer li_RespStatusCode string ls_Id string ls_First_name string ls_Last_name string ls_Email integer li_V_type integer li_Pmi string ls_Timezone integer li_Verified string ls_Created_at string ls_Last_login_time string ls_Language string ls_Phone_number string ls_Status string ls_Role_id integer li_Page_count integer li_Page_number integer li_Page_size integer li_Total_records integer i integer li_Count_i // 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... ls_ApiKey = "o9rw6Gq0RnqlkfaSqtCMOA" ls_ApiSecret = "UslmE23Kjh7at9z3If1xAHEyLmPDNxvxQrjR" // Create a JWT to authenticate Zoom API requests. loo_Jwt = create oleobject // Use "Chilkat_9_5_0.Jwt" for versions of Chilkat < 10.0.0 li_rc = loo_Jwt.ConnectToNewObject("Chilkat.Jwt") if li_rc < 0 then destroy loo_Jwt MessageBox("Error","Connecting to COM object failed") return end if loo_Jose = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_Jose.ConnectToNewObject("Chilkat.JsonObject") li_Success = loo_Jose.UpdateString("alg","HS256") li_Success = loo_Jose.UpdateString("typ","JWT") // Build claims to look like this: // {"aud":null,"iss":"o9rw6Gq0RnqlkfaSqtCMOA","exp":1627651762,"iat":1627646363} loo_Claims = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_Claims.ConnectToNewObject("Chilkat.JsonObject") li_Success = loo_Claims.UpdateString("iss",ls_ApiKey) li_Success = loo_Claims.UpdateNull("aud") // Set the timestamp of when the JWT was created to now. li_CurDateTime = loo_Jwt.GenNumericDate(0) li_Success = loo_Claims.AddIntAt(-1,"iat",li_CurDateTime) // Set the timestamp defining an expiration time (end time) for the token // to be now + 1 month(3600 * 24 * 30 seconds) li_OneMonth = 3600 * 24 * 30 li_Success = loo_Claims.AddIntAt(-1,"exp",li_CurDateTime + li_OneMonth) // Produce the smallest possible JWT: loo_Jwt.AutoCompact = 1 ls_StrJwt = loo_Jwt.CreateJwt(loo_Jose.Emit(),loo_Claims.Emit(),ls_ApiSecret) Write-Debug ls_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 loo_Http = create oleobject // Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 li_rc = loo_Http.ConnectToNewObject("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 loo_Http.SetRequestHeader("content-type","application/json") // Adds the "Authorization: Bearer { your_token }" header. loo_Http.AuthToken = ls_StrJwt loo_SbResponseBody = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder") li_Success = loo_Http.QuickGetSb("https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1",loo_SbResponseBody) if li_Success = 0 then Write-Debug loo_Http.LastErrorText destroy loo_Jwt destroy loo_Jose destroy loo_Claims destroy loo_Http destroy loo_SbResponseBody return end if loo_JResp = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject") loo_JResp.LoadSb(loo_SbResponseBody) loo_JResp.EmitCompact = 0 Write-Debug "Response Body:" Write-Debug loo_JResp.Emit() li_RespStatusCode = loo_Http.LastStatus Write-Debug "Response Status Code = " + string(li_RespStatusCode) if li_RespStatusCode >= 400 then Write-Debug "Response Header:" Write-Debug loo_Http.LastHeader Write-Debug "Failed." destroy loo_Jwt destroy loo_Jose destroy loo_Claims destroy loo_Http destroy loo_SbResponseBody destroy loo_JResp return end if // 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 li_Page_count = loo_JResp.IntOf("page_count") li_Page_number = loo_JResp.IntOf("page_number") li_Page_size = loo_JResp.IntOf("page_size") li_Total_records = loo_JResp.IntOf("total_records") i = 0 li_Count_i = loo_JResp.SizeOfArray("users") do while i < li_Count_i loo_JResp.I = i ls_Id = loo_JResp.StringOf("users[i].id") ls_First_name = loo_JResp.StringOf("users[i].first_name") ls_Last_name = loo_JResp.StringOf("users[i].last_name") ls_Email = loo_JResp.StringOf("users[i].email") li_V_type = loo_JResp.IntOf("users[i].type") li_Pmi = loo_JResp.IntOf("users[i].pmi") ls_Timezone = loo_JResp.StringOf("users[i].timezone") li_Verified = loo_JResp.IntOf("users[i].verified") ls_Created_at = loo_JResp.StringOf("users[i].created_at") ls_Last_login_time = loo_JResp.StringOf("users[i].last_login_time") ls_Language = loo_JResp.StringOf("users[i].language") ls_Phone_number = loo_JResp.StringOf("users[i].phone_number") ls_Status = loo_JResp.StringOf("users[i].status") ls_Role_id = loo_JResp.StringOf("users[i].role_id") i = i + 1 loop destroy loo_Jwt destroy loo_Jose destroy loo_Claims destroy loo_Http destroy loo_SbResponseBody destroy loo_JResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.