Always 401 from https://api.zoom.us/v2/users

Description
https://api.zoom.us/v2/users/{userid}/token always return 401.

Error
it returns ,

124 Invalid access token.

Which App Type (OAuth / Chatbot / JWT / Webhook)?
api

Which Endpoint/s?
https://api.zoom.us/v2/users/{userid}/tokenhttps://api.zoom.us/v2/users/{userid}/token

When i create a jwt with credentials from developer console and try to send a get request it always returns 401 error. But with same credentials i am able to build simple app which creates and joins room.

this is my code :

private String getZoomToken() {
    try {
    URL zoomTokenEndpoint = new URL("https://api.zoom.us/v2/users/" + "bhdrgl06@gmail.com" + "/token?type=token&access_token=" + getJWT());
    HttpsURLConnection connection = (HttpsURLConnection) zoomTokenEndpoint.openConnection();
    if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
        InputStream responseBody = connection.getInputStream();
        InputStreamReader responseBodyReader = new InputStreamReader(responseBody, "UTF-8");
        BufferedReader streamReader = new BufferedReader(responseBodyReader);
        StringBuilder responseStrBuilder = new StringBuilder();

        //get JSON String
        String inputStr;
        while ((inputStr = streamReader.readLine()) != null)
            responseStrBuilder.append(inputStr);

        connection.disconnect();
        JSONObject jsonObject = new JSONObject(responseStrBuilder.toString());
        return jsonObject.getString("token");
    } else {
        Log.d("dasdas", "error in connection");
        return null;
    }
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return "";
}

private String getJWT() {
    long time = System.currentTimeMillis()/1000  + 3600;

    String header = "{\"alg\": \"HS256\", \"typ\": \"JWT\"}";
    String payload = "{\"iss\": \"" + AppConstant.Zoom_Key + "\"" + ", \"exp\": " + String.valueOf(time) + "}";
    try {
        String headerBase64Str = Base64.encodeToString(header.getBytes("utf-8"), Base64.NO_WRAP| Base64.NO_PADDING | Base64.URL_SAFE);
        String payloadBase64Str = Base64.encodeToString(payload.getBytes("utf-8"), Base64.NO_WRAP| Base64.NO_PADDING | Base64.URL_SAFE);
        final Mac mac = Mac.getInstance("HmacSHA256");
        SecretKeySpec secretKeySpec = new SecretKeySpec(AppConstant.Zoom_Secret.getBytes(), "HmacSHA256");
        mac.init(secretKeySpec);

        byte[] digest = mac.doFinal((headerBase64Str + "." + payloadBase64Str).getBytes());

        return headerBase64Str + "." + payloadBase64Str + "." + Base64.encodeToString(digest, Base64.NO_WRAP| Base64.NO_PADDING | Base64.URL_SAFE);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (InvalidKeyException e) {
        e.printStackTrace();
    }
    return  "";
}

it caused most stupid mistake ever. About crentials. Now i am able to do make request. Bu it returns empty not token

Hey @bgul,

Are you still having an issue with this request? Can you share an example of the latest request where you’re getting an empty token? We’re happy to take a closer look.

Thanks,
Will

Hi @will.zoom,

Thank you for your response,
Below request returns as success but has empty json response

https://api.zoom.us/v2/users/ValidUserMail/token?type=token&access_token=e

I also called same method with id of same user instead email from below service

String url = “https://api.zoom.us/v2/users?access_token=” + token

Hey @bgul,

Please try passing in the access token via the header instead of a query param in the request url.

Example:

"Authorization": "Basic ACCESS_TOKEN_HERE"

Docs here:

Thanks,
Tommy

actually both of them was working. Problem was i signed in google. When i sign-up from different accout it was all fine. After that to add user and get zak i needed to upgrade my account to pro.

Hey @bgul,

Thank you for the update. I’m glad to hear that you resolved your issues! If you encounter any further issues or questions, please don’t hesitate to reach out.

Thanks,
Max

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.