Sample code for 30+ languages & platforms
Objective-C

Zoom API - Create JWT to Authenticate API Requests

See more Zoom Examples

Creates a JWT for the Zoom API.

Chilkat Objective-C Downloads

Objective-C
#import <NSString.h>
#import <CkoJwt.h>
#import <CkoJsonObject.h>
#import <CkoHttp.h>
#import <CkoStringBuilder.h>

BOOL success = NO;

// 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...
NSString *apiKey = @"o9rw6Gq0RnqlkfaSqtCMOA";
NSString *apiSecret = @"UslmE23Kjh7at9z3If1xAHEyLmPDNxvxQrjR";

// Create a JWT to authenticate Zoom API requests.
CkoJwt *jwt = [[CkoJwt alloc] init];

CkoJsonObject *jose = [[CkoJsonObject alloc] init];
success = [jose UpdateString: @"alg" value: @"HS256"];
success = [jose UpdateString: @"typ" value: @"JWT"];

// Build claims to look like this:
// {"aud":null,"iss":"o9rw6Gq0RnqlkfaSqtCMOA","exp":1627651762,"iat":1627646363}
CkoJsonObject *claims = [[CkoJsonObject alloc] init];
success = [claims UpdateString: @"iss" value: apiKey];
success = [claims UpdateNull: @"aud"];

// Set the timestamp of when the JWT was created to now.
int curDateTime = [[jwt GenNumericDate: [NSNumber numberWithInt: 0]] intValue];
success = [claims AddIntAt: [NSNumber numberWithInt: -1] name: @"iat" value: [NSNumber numberWithInt: curDateTime]];

// Set the timestamp defining an expiration time (end time) for the token
// to be now + 1 month(3600 * 24 * 30 seconds)
int oneMonth = 3600 * 24 * 30;
success = [claims AddIntAt: [NSNumber numberWithInt: -1] name: @"exp" value: [NSNumber numberWithInt: (curDateTime + oneMonth)]];

// Produce the smallest possible JWT:
jwt.AutoCompact = YES;

NSString *strJwt = [jwt CreateJwt: [jose Emit] payload: [claims Emit] password: apiSecret];

NSLog(@"%@",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

CkoHttp *http = [[CkoHttp alloc] init];

// 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 SetRequestHeader: @"content-type" value: @"application/json"];
// Adds the "Authorization: Bearer { your_token }" header.
http.AuthToken = strJwt;

CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [http QuickGetSb: @"https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1" sbContent: sbResponseBody];
if (success == NO) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

CkoJsonObject *jResp = [[CkoJsonObject alloc] init];
[jResp LoadSb: sbResponseBody];
jResp.EmitCompact = NO;

NSLog(@"%@",@"Response Body:");
NSLog(@"%@",[jResp Emit]);

int respStatusCode = [http.LastStatus intValue];
NSLog(@"%@%d",@"Response Status Code = ",respStatusCode);
if (respStatusCode >= 400) {
    NSLog(@"%@",@"Response Header:");
    NSLog(@"%@",http.LastHeader);
    NSLog(@"%@",@"Failed.");
    return;
}

// 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

NSString *id = 0;
NSString *first_name = 0;
NSString *last_name = 0;
NSString *email = 0;
int v_type;
int pmi;
NSString *timezone = 0;
int verified;
NSString *created_at = 0;
NSString *last_login_time = 0;
NSString *language = 0;
NSString *phone_number = 0;
NSString *status = 0;
NSString *role_id = 0;

int page_count = [[jResp IntOf: @"page_count"] intValue];
int page_number = [[jResp IntOf: @"page_number"] intValue];
int page_size = [[jResp IntOf: @"page_size"] intValue];
int total_records = [[jResp IntOf: @"total_records"] intValue];
int i = 0;
int count_i = [[jResp SizeOfArray: @"users"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    id = [jResp StringOf: @"users[i].id"];
    first_name = [jResp StringOf: @"users[i].first_name"];
    last_name = [jResp StringOf: @"users[i].last_name"];
    email = [jResp StringOf: @"users[i].email"];
    v_type = [[jResp IntOf: @"users[i].type"] intValue];
    pmi = [[jResp IntOf: @"users[i].pmi"] intValue];
    timezone = [jResp StringOf: @"users[i].timezone"];
    verified = [[jResp IntOf: @"users[i].verified"] intValue];
    created_at = [jResp StringOf: @"users[i].created_at"];
    last_login_time = [jResp StringOf: @"users[i].last_login_time"];
    language = [jResp StringOf: @"users[i].language"];
    phone_number = [jResp StringOf: @"users[i].phone_number"];
    status = [jResp StringOf: @"users[i].status"];
    role_id = [jResp StringOf: @"users[i].role_id"];
    i = i + 1;
}