Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Tcl Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
AWS Security Token Service
AWS Translate
Activix CRM
Adyen
Alibaba Cloud OSS
Amazon Cognito
Amazon DynamoDB
Amazon MWS
Amazon Pay
Amazon Rekognition
Amazon SP-API
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Banco Inter
Belgian eHealth Platform
Bitfinex v2 REST
Bluzone
BrickLink
Bunny CDN
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Egypt eReceipt
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Google Translate
Google Vision
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
JCC Cyprus
Jira
Lightspeed
MYOB
Magento
Mailgun
Malaysia MyInvois

Mastercard
MedTunnel
MercadoLibre
MessageMedia
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Moody's
Okta OAuth/OIDC
OneLogin OIDC
OneNote
OpenAI ChatGPT
PRODA
PayPal
Paynow.pl
Peoplevox
Populi
QuickBooks
Rabobank
Refinitiv
Royal Mail OBA
SCiS Schools Catalogue
SII Chile
SMSAPI
SOAP finkok.com
Salesforce
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
TikTok Shop
Trello
Twilio
Twitter API v2
Twitter v1
UPS
UniPin
VoiceBase
Vonage
WaTrend
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yapily
Yousign
ZATCA
Zendesk
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(Tcl) Zoom API - Create JWT to Authenticate API Requests

See more Zoom Examples

Creates a JWT for the Zoom API.

For more information, see https://marketplace.zoom.us/docs/api-reference/using-zoom-apis#using-jwt

Chilkat Tcl Extension Downloads

Chilkat Tcl Extension Downloads

load ./chilkat.dll

# 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...
set apiKey "o9rw6Gq0RnqlkfaSqtCMOA"
set apiSecret "UslmE23Kjh7at9z3If1xAHEyLmPDNxvxQrjR"

# Create a JWT to authenticate Zoom API requests.
set jwt [new_CkJwt]

set jose [new_CkJsonObject]

set success [CkJsonObject_UpdateString $jose "alg" "HS256"]
set success [CkJsonObject_UpdateString $jose "typ" "JWT"]

# Build claims to look like this:
# {"aud":null,"iss":"o9rw6Gq0RnqlkfaSqtCMOA","exp":1627651762,"iat":1627646363}
set claims [new_CkJsonObject]

set success [CkJsonObject_UpdateString $claims "iss" $apiKey]
set success [CkJsonObject_UpdateNull $claims "aud"]

# Set the timestamp of when the JWT was created to now.
set curDateTime [CkJwt_GenNumericDate $jwt 0]
set success [CkJsonObject_AddIntAt $claims -1 "iat" $curDateTime]

# Set the timestamp defining an expiration time (end time) for the token
# to be now + 1 month(3600 * 24 * 30 seconds)
set oneMonth [expr 3600 * [expr 24 * 30]]
set success [CkJsonObject_AddIntAt $claims -1 "exp" [expr $curDateTime + $oneMonth]]

# Produce the smallest possible JWT:
CkJwt_put_AutoCompact $jwt 1

set strJwt [CkJwt_createJwt $jwt [CkJsonObject_emit $jose] [CkJsonObject_emit $claims] $apiSecret]

puts "$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

set http [new_CkHttp]

# 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

CkHttp_SetRequestHeader $http "content-type" "application/json"
# Adds the "Authorization: Bearer { your_token }" header.
CkHttp_put_AuthToken $http $strJwt

set sbResponseBody [new_CkStringBuilder]

set success [CkHttp_QuickGetSb $http "https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1" $sbResponseBody]
if {$success == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkJwt $jwt
    delete_CkJsonObject $jose
    delete_CkJsonObject $claims
    delete_CkHttp $http
    delete_CkStringBuilder $sbResponseBody
    exit
}

set jResp [new_CkJsonObject]

CkJsonObject_LoadSb $jResp $sbResponseBody
CkJsonObject_put_EmitCompact $jResp 0

puts "Response Body:"
puts [CkJsonObject_emit $jResp]

set respStatusCode [CkHttp_get_LastStatus $http]
puts "Response Status Code = $respStatusCode"
if {$respStatusCode >= 400} then {
    puts "Response Header:"
    puts [CkHttp_lastHeader $http]
    puts "Failed."
    delete_CkJwt $jwt
    delete_CkJsonObject $jose
    delete_CkJsonObject $claims
    delete_CkHttp $http
    delete_CkStringBuilder $sbResponseBody
    delete_CkJsonObject $jResp
    exit
}

# 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

set page_count [CkJsonObject_IntOf $jResp "page_count"]
set page_number [CkJsonObject_IntOf $jResp "page_number"]
set page_size [CkJsonObject_IntOf $jResp "page_size"]
set total_records [CkJsonObject_IntOf $jResp "total_records"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "users"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set id [CkJsonObject_stringOf $jResp "users[i].id"]
    set first_name [CkJsonObject_stringOf $jResp "users[i].first_name"]
    set last_name [CkJsonObject_stringOf $jResp "users[i].last_name"]
    set email [CkJsonObject_stringOf $jResp "users[i].email"]
    set v_type [CkJsonObject_IntOf $jResp "users[i].type"]
    set pmi [CkJsonObject_IntOf $jResp "users[i].pmi"]
    set timezone [CkJsonObject_stringOf $jResp "users[i].timezone"]
    set verified [CkJsonObject_IntOf $jResp "users[i].verified"]
    set created_at [CkJsonObject_stringOf $jResp "users[i].created_at"]
    set last_login_time [CkJsonObject_stringOf $jResp "users[i].last_login_time"]
    set language [CkJsonObject_stringOf $jResp "users[i].language"]
    set phone_number [CkJsonObject_stringOf $jResp "users[i].phone_number"]
    set status [CkJsonObject_stringOf $jResp "users[i].status"]
    set role_id [CkJsonObject_stringOf $jResp "users[i].role_id"]
    set i [expr $i + 1]
}

delete_CkJwt $jwt
delete_CkJsonObject $jose
delete_CkJsonObject $claims
delete_CkHttp $http
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.