# Getting 401 error while fetching Zoom Access Token

**URL:** <https://devforum.zoom.us/t/getting-401-error-while-fetching-zoom-access-token/59186>\
**Category:** API and Webhooks\
**Created:** [October 21, 2021, 1:59pm UTC](https://devforum.zoom.us/t/getting-401-error-while-fetching-zoom-access-token/59186 "2021-10-21T13:59:07Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Megha1](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/megha1/32/17391_2.png) [@Megha1](https://devforum.zoom.us/u/Megha1)\
**Post date:** [October 21, 2021, 1:59pm UTC](https://devforum.zoom.us/t/getting-401-error-while-fetching-zoom-access-token/59186/1 "2021-10-21T13:59:07Z")

</div>

Hello Zoom Team,

I am using Android Meeting Sdk with SDK app with version 5.7.1.1267 and creating Json Web Token in backend which is required to fetch Zoom Access Token using [jwt.io](http://jwt.io) library and following code:

> Date now = new Date(nowMillis);  
> long expMillis = nowMillis + 86400;  
> Date exp = new Date(expMillis);  
> String jwtToken = Jwts.builder()  
> .claim(“name”, “Jane Doe”)  
> .claim(“email”, “[jane@example.com](mailto:jane@example.com)”)  
> .setSubject(“jane”)  
> .setId(UUID.randomUUID().toString())  
> .setIssuedAt(now)  
> .setExpiration(exp)  
> .compact();

I am sending **[https://api.zoom.us/v2/users/me/token](https://api.zoom.us/v2/users/me/token)** to get Zoom Access Token, but I am not getting token, I am getting error 401.

Please help me out from this situation and suggest changes to be done.

Thank you  
Megha

---

<div class="post-metadata">

**Author:** ![gianni.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/gianni.zoom/32/32523_2.png) [@gianni.zoom](https://devforum.zoom.us/u/gianni.zoom)\
**Post date:** [October 21, 2021, 5:39pm UTC](https://devforum.zoom.us/t/getting-401-error-while-fetching-zoom-access-token/59186/2 "2021-10-21T17:39:11Z")

</div>

Hi @Megha1 ,

Moved this to the correct topic and someone from there will be able to assist you 🙂

Gianni

---

<div class="post-metadata">

**Author:** ![Megha1](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/megha1/32/17391_2.png) [@Megha1](https://devforum.zoom.us/u/Megha1)\
**Post date:** [October 21, 2021, 5:56pm UTC](https://devforum.zoom.us/t/getting-401-error-while-fetching-zoom-access-token/59186/3 "2021-10-21T17:56:15Z")

</div>

Hi @gianni.zoom,

Should I switch to API And Webhooks?

---

<div class="post-metadata">

**Author:** ![gianni.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/gianni.zoom/32/32523_2.png) [@gianni.zoom](https://devforum.zoom.us/u/gianni.zoom)\
**Post date:** [October 21, 2021, 7:59pm UTC](https://devforum.zoom.us/t/getting-401-error-while-fetching-zoom-access-token/59186/4 "2021-10-21T19:59:15Z")

</div>

Hi @Megha1 , it should be in Android Meeting SDK where I moved it; I’ll move it back there.

---

<div class="post-metadata">

**Author:** ![Megha1](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/megha1/32/17391_2.png) [@Megha1](https://devforum.zoom.us/u/Megha1)\
**Post date:** [October 22, 2021, 4:44am UTC](https://devforum.zoom.us/t/getting-401-error-while-fetching-zoom-access-token/59186/5 "2021-10-22T04:44:46Z")

</div>

Hi @gianni.zoom, Please tell who can assist me?

Thank you

---

<div class="post-metadata">

**Author:** ![gianni.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/gianni.zoom/32/32523_2.png) [@gianni.zoom](https://devforum.zoom.us/u/gianni.zoom)\
**Post date:** [October 22, 2021, 2:14pm UTC](https://devforum.zoom.us/t/getting-401-error-while-fetching-zoom-access-token/59186/6 "2021-10-22T14:14:35Z")

</div>

@Megha1 – this is my mistake. You placed in the right spot initially because the error is pertaining to the API. Please excuse me, so I’ll move it back.

In this post you said the request is working in Postman, but not via your front end code:

> [@How to get Zoom Access Token and Schedule Meeting Using Api in Android Meeting sdk in v5.7.1.1267](https://devforum.zoom.us/t/how-to-get-zoom-access-token-and-schedule-meeting-using-api-in-android-meeting-sdk-in-v5-7-1-1267/57279/9):
>
> hey @MaxM, Thank you for reply! I would like to ask to you If I can hit the Zoom API from frontend android studio also, because I am getting 401 error code from frontend but that is working when I am calling the same through Postman. Thank you Megha

Could you please clarify if that is still the case?

Thanks!

---

<div class="post-metadata">

**Author:** ![Megha1](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/megha1/32/17391_2.png) [@Megha1](https://devforum.zoom.us/u/Megha1)\
**Post date:** [October 25, 2021, 6:19am UTC](https://devforum.zoom.us/t/getting-401-error-while-fetching-zoom-access-token/59186/8 "2021-10-25T06:19:12Z")

</div>

Hi @gianni.zoom,

That was my previous discussion but now I am using Android Meeting Sdk with SDK app with version 5.7.1.1267 and creating Json Web Token in backend using java and maven which is required to fetch Zoom Access Token using [jwt.io](http://jwt.io) library and following code to generate token :

> String secret = SDK\_SECRET;  
> Key hmacKey = new SecretKeySpec(Base64.getDecoder().decode(secret),  
> SignatureAlgorithm.HS256.getJcaName());  
> long nowMillis = System.currentTimeMillis()/1000;  
> Date now = new Date(nowMillis);  
> long expMillis = nowMillis + 86400;  
> Date exp = new Date(expMillis);  
> String jwtToken = Jwts.builder()  
> .claim(“name”, “Jane Doe”)  
> .claim(“email”, “[jane@example.com](mailto:jane@example.com)”)  
> .setSubject(“jane”)  
> .setId(UUID.randomUUID().toString())  
> .setIssuedAt(now)  
> .setExpiration(exp)  
> .signWith(hmacKey);  
> .compact();

I am using SDK\_KEY and SDK\_SECRET given in Sdk app and using this method to hit the API :

> try {  
> String zoomUrl = “[https://api.zoom.us/v2/users/me/token”](https://api.zoom.us/v2/users/me/token%E2%80%9D);  
> URL url = new URL(zoomUrl);  
> HttpURLConnection connection = (HttpURLConnection) url.openConnection();  
> connection.setRequestMethod(“POST”);  
> connection.setRequestProperty (“Authorization”, jwtToken);  
> connection.setDoOutput(true);  
> int responseCode = connection.getResponseCode();  
> String responseFromZoom = “”;  
> String zoomResult = “”;  
> InputStream is = connection.getInputStream();  
> BufferedReader responseReader = new BufferedReader(new InputStreamReader(is));  
> while ((responseFromZoom = responseReader.readLine()) != null) {  
> zoomResult += responseFromZoom;  
> }  
> responseReader.close();  
> } catch (Exception exception) {  
> exception.printStackTrace();  
> }

I am sending **[https://api.zoom.us/v2/users/me/token](https://api.zoom.us/v2/users/me/token)** to get Zoom Access Token, but I am not getting token, I am getting error 401 in response from zoom.

Please help me out from this situation and tell me where I am going wrong and suggest changes to be done to correct this.

Thank you  
Megha

---

<div class="post-metadata">

**Author:** ![Megha1](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/megha1/32/17391_2.png) [@Megha1](https://devforum.zoom.us/u/Megha1)\
**Post date:** [October 25, 2021, 5:11pm UTC](https://devforum.zoom.us/t/getting-401-error-while-fetching-zoom-access-token/59186/9 "2021-10-25T17:11:49Z")

</div>

Hi @gianni.zoom ,

I tried another method to create JWT:

Date currentDate = new Date();  
long currentTime = currentDate.getTime()/1000;  
String secret = SDK\_SECRET;  
JsonObject payload = new JsonObject();  
payload.addProperty(“appKey”, appProps.getProperty(“zoom.sdkKey”));  
payload.addProperty(“iat”, currentTime);  
payload.addProperty(“exp”, currentTime+86400);  
payload.addProperty(“tokenExp”, currentTime+86400);  
JsonObject header = new JsonObject();  
header.addProperty(“alg”, “HS256”);  
header.addProperty(“typ”, “JWT”);

> String jwtToken;  
> try {  
> String signature = hmacSha256(  
> Base64.getEncoder().encodeToString(header.toString().getBytes(“UTF-8”))  
> + “.” + Base64.getEncoder().encodeToString(payload.toString().getBytes(“UTF-8”)),  
> secret);  
> jwtToken = Base64.getEncoder().encodeToString(header.toString().getBytes(“UTF-8”)) + “.” + Base64.getEncoder().encodeToString(payload.toString().getBytes(“UTF-8”)) + “.” + signature;  
> } catch (UnsupportedEncodingException e) {  
> e.printStackTrace();  
> return “”;  
> }

> private static String encode(byte bytes) {  
> return Base64.getUrlEncoder().withoutPadding().encodeToString(bytes);  
> }

```
private String hmacSha256(String data, String secret) {
    try {
        byte[] hash = secret.getBytes(StandardCharsets.UTF_8);
        Mac sha256Hmac = Mac.getInstance("HmacSHA256");
        SecretKeySpec secretKey = new SecretKeySpec(hash, "HmacSHA256");
        sha256Hmac.init(secretKey);
        byte[] signedBytes = sha256Hmac.doFinal(data.getBytes(StandardCharsets.UTF_8));
        return encode(signedBytes);
    } catch (Exception ex) {
        ex.printStackTrace();
    	return null;
    }
}		

```

and using same method to fetch ZAK but this is also not working as I am getting same 401 error.

Please suggest me what should I do next and where I am wrong if possible as I tried with postman also and I am getting same there with message “Invalid access token”.

Thank you

---

<div class="post-metadata">

**Author:** ![gianni.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/gianni.zoom/32/32523_2.png) [@gianni.zoom](https://devforum.zoom.us/u/gianni.zoom)\
**Post date:** [October 26, 2021, 4:39pm UTC](https://devforum.zoom.us/t/getting-401-error-while-fetching-zoom-access-token/59186/10 "2021-10-26T16:39:59Z")

</div>

Hi @Megha1 ,

Thanks for this! Can you send your full details to [developersupport@zoom.us](mailto:developersupport@zoom.us) addressed to me so I can help debug and test on my end?

Thank you!

---

<div class="post-metadata">

**Author:** ![Megha1](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/megha1/32/17391_2.png) [@Megha1](https://devforum.zoom.us/u/Megha1)\
**Post date:** [October 26, 2021, 5:12pm UTC](https://devforum.zoom.us/t/getting-401-error-while-fetching-zoom-access-token/59186/11 "2021-10-26T17:12:59Z")

</div>

Hi @gianni.zoom,

Thanks for the post, I will mail there

---

<div class="post-metadata">

**Author:** ![MaxM](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/maxm/32/42303_2.png) [@MaxM](https://devforum.zoom.us/u/MaxM)\
**Post date:** [October 27, 2021, 11:06pm UTC](https://devforum.zoom.us/t/getting-401-error-while-fetching-zoom-access-token/59186/12 "2021-10-27T23:06:22Z")

</div>

Thank you @Megha1!

Max

---

<div class="post-metadata">

**Author:** ![MaxM](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/maxm/32/42303_2.png) [@MaxM](https://devforum.zoom.us/u/MaxM)\
**Post date:** [October 27, 2021, 11:06pm UTC](https://devforum.zoom.us/t/getting-401-error-while-fetching-zoom-access-token/59186/13 "2021-10-27T23:06:29Z")

</div>


