Sample code for 30+ languages & platforms
Java

Zoom API - Create JWT to Authenticate API Requests

See more Zoom Examples

Creates a JWT for the Zoom API.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.Jwt;
import com.chilkatsoft.chilkat2.StringBuilder;

public class ChilkatExample {

    public static void main(String[] args) {
        // 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...
        String apiKey = "o9rw6Gq0RnqlkfaSqtCMOA";
        String apiSecret = "UslmE23Kjh7at9z3If1xAHEyLmPDNxvxQrjR";

        // Create a JWT to authenticate Zoom API requests.
        Jwt jwt = new Jwt();

        JsonObject jose = new JsonObject();
        jose.updateString("alg", "HS256");
        jose.updateString("typ", "JWT");

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

        // Set the timestamp of when the JWT was created to now.
        int 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)
        int oneMonth = 3600 * 24 * 30;
        claims.addIntAt(-1, "exp", curDateTime + oneMonth);

        // Produce the smallest possible JWT:
        jwt.setAutoCompact(true);

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

        System.out.println(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

        Http http = new 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

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

        StringBuilder sbResponseBody = new StringBuilder();
        try {
            http.quickGetSb("https://api.zoom.us/v2/users?status=active&page_size=30&page_number=1", sbResponseBody);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        JsonObject jResp = new JsonObject();
        jResp.loadSb(sbResponseBody);
        jResp.setEmitCompact(false);

        System.out.println("Response Body:");
        System.out.println(jResp.emit());

        int respStatusCode = http.getLastStatus();
        System.out.println("Response Status Code = " + respStatusCode);
        if (respStatusCode >= 400) {
            System.out.println("Response Header:");
            System.out.println(http.getLastHeader());
            System.out.println("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

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

        int page_count = jResp.intOf("page_count");
        int page_number = jResp.intOf("page_number");
        int page_size = jResp.intOf("page_size");
        int total_records = jResp.intOf("total_records");
        int i = 0;
        int count_i = jResp.sizeOfArray("users");
        while (i < count_i) {
            jResp.setI(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");
            pmi = jResp.intOf("users[i].pmi");
            timezone = jResp.stringOf("users[i].timezone");
            verified = jResp.intOf("users[i].verified");
            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;
        }
    }
}