Sample code for 30+ languages & platforms
Dart

Zoom API - Create JWT to Authenticate API Requests

See more Zoom Examples

Creates a JWT for the Zoom API.

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  // 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...
  final apiKey = 'o9rw6Gq0RnqlkfaSqtCMOA';
  final apiSecret = 'UslmE23Kjh7at9z3If1xAHEyLmPDNxvxQrjR';

  // Create a JWT to authenticate Zoom API requests.
  final jwt = CkJwt();

  final jose = CkJsonObject();
  jose.updateString('alg', 'HS256');
  jose.updateString('typ', 'JWT');

  // Build claims to look like this:
  // {"aud":null,"iss":"o9rw6Gq0RnqlkfaSqtCMOA","exp":1627651762,"iat":1627646363}
  final claims = CkJsonObject();
  claims.updateString('iss', apiKey);
  claims.updateNull('aud');

  // Set the timestamp of when the JWT was created to now.
  final curDateTime = jwt.genNumericDate(0);
  claims.addIntAt(-1, 'iat', curDateTime);

  // Set the timestamp defining an expiration time (end time) for the token
  // to be now + 1 month(3600 * 24 * 30 seconds)
  final oneMonth = 3600 * 24 * 30;
  claims.addIntAt(-1, 'exp', curDateTime + oneMonth);

  // Produce the smallest possible JWT:
  jwt.autoCompact = true;

  final strJwt = jwt.createJwt(jose.emit(), claims.emit(), apiSecret);

  print(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

  final http = 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

  http.setRequestHeader('content-type', 'application/json');
  // Adds the "Authorization: Bearer { your_token }" header.
  http.authToken = strJwt;

  final sbResponseBody = CkStringBuilder();
  try {
    http.quickGetSb('https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1', sbResponseBody);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final jResp = CkJsonObject();
  jResp.loadSb(sbResponseBody);
  jResp.emitCompact = false;

  print('Response Body:');
  print(jResp.emit());

  final respStatusCode = http.lastStatus;
  print('Response Status Code = $respStatusCode');
  if (respStatusCode >= 400) {
    print('Response Header:');
    print(http.lastHeader);
    print('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

  var id = '';
  var firstName = '';
  var lastName = '';
  var email = '';
  var vType = 0;
  var pmi = 0;
  var timezone = '';
  var verified = 0;
  var createdAt = '';
  var lastLoginTime = '';
  var language = '';
  var phoneNumber = '';
  var status = '';
  var roleId = '';

  final pageCount = jResp.intOf('page_count');
  final pageNumber = jResp.intOf('page_number');
  final pageSize = jResp.intOf('page_size');
  final totalRecords = jResp.intOf('total_records');
  var i = 0;
  final countI = jResp.sizeOfArray('users');
  while (i < countI) {
    jResp.i = i;
    id = jResp.stringOf('users[i].id');
    firstName = jResp.stringOf('users[i].first_name');
    lastName = jResp.stringOf('users[i].last_name');
    email = jResp.stringOf('users[i].email');
    vType = jResp.intOf('users[i].type');
    pmi = jResp.intOf('users[i].pmi');
    timezone = jResp.stringOf('users[i].timezone');
    verified = jResp.intOf('users[i].verified');
    createdAt = jResp.stringOf('users[i].created_at');
    lastLoginTime = jResp.stringOf('users[i].last_login_time');
    language = jResp.stringOf('users[i].language');
    phoneNumber = jResp.stringOf('users[i].phone_number');
    status = jResp.stringOf('users[i].status');
    roleId = jResp.stringOf('users[i].role_id');
    i++;
  }
}