# {"code":124,"message":"Invalid access token."} - Android/Java

**URL:** <https://devforum.zoom.us/t/code-124-message-invalid-access-token-android-java/811>\
**Category:** API and Webhooks\
**Created:** [December 5, 2017, 2:49pm UTC](https://devforum.zoom.us/t/code-124-message-invalid-access-token-android-java/811 "2017-12-05T14:49:37Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben\_Cheeseman](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@Ben\_Cheeseman](https://devforum.zoom.us/u/Ben_Cheeseman)\
**Post date:** [December 5, 2017, 2:49pm UTC](https://devforum.zoom.us/t/code-124-message-invalid-access-token-android-java/811/1 "2017-12-05T14:49:37Z")

</div>

We are having some issues accessing the [https://api.zoom.us/v2/users](https://api.zoom.us/v2/users) API. We are getting&nbsp;{“code”:124,“message”:“Invalid access token.”}.&nbsp;

&nbsp;

This is the code snippet I have used in generating a key:&nbsp;

&nbsp;

&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JSONObject header = new JSONObject();

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; header.put(“alg”, “HS256”);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; header.put(“typ”, “JWT”);

&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JSONObject claim = new JSONObject();

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; claim.put(“exp”, System.currentTimeMillis() + 86400000);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; claim.put(“iss”, Keys.API\_KEY);

&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; compactJws = Jwts.builder()

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .setHeader(header)

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .setClaims(claim)

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .setIssuer(Keys.API\_KEY)

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .signWith(SignatureAlgorithm.HS256, Keys.API\_SECRET.getBytes())

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .compact();```

---

<div class="post-metadata">

**Author:** ![Joshua\_Woodward1](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/joshua_woodward1/32/1480_2.png) [@Joshua\_Woodward1](https://devforum.zoom.us/u/Joshua_Woodward1)\
**Post date:** [December 5, 2017, 5:20pm UTC](https://devforum.zoom.us/t/code-124-message-invalid-access-token-android-java/811/2 "2017-12-05T17:20:08Z")

</div>

Hi Ben,

This error indicates there is something wrong with your token generation. Not sure the language or library you are using, but start there.

---

<div class="post-metadata">

**Author:** ![Ben\_Cheeseman](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@Ben\_Cheeseman](https://devforum.zoom.us/u/Ben_Cheeseman)\
**Post date:** [December 5, 2017, 5:53pm UTC](https://devforum.zoom.us/t/code-124-message-invalid-access-token-android-java/811/3 "2017-12-05T17:53:47Z")

</div>

We are using android/java

---

<div class="post-metadata">

**Author:** ![Joshua\_Woodward1](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/joshua_woodward1/32/1480_2.png) [@Joshua\_Woodward1](https://devforum.zoom.us/u/Joshua_Woodward1)\
**Post date:** [December 5, 2017, 7:35pm UTC](https://devforum.zoom.us/t/code-124-message-invalid-access-token-android-java/811/4 "2017-12-05T19:35:36Z")

</div>

Are you using one of the libraries on&nbsp;[https://jwt.io/#libraries](https://jwt.io/#libraries) ?

---

<div class="post-metadata">

**Author:** ![Ben\_Cheeseman](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@Ben\_Cheeseman](https://devforum.zoom.us/u/Ben_Cheeseman)\
**Post date:** [December 6, 2017, 3:35pm UTC](https://devforum.zoom.us/t/code-124-message-invalid-access-token-android-java/811/5 "2017-12-06T15:35:46Z")

</div>

Yes we are using only libraries that you listed there.&nbsp;

---

<div class="post-metadata">

**Author:** ![Ben\_Cheeseman](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@Ben\_Cheeseman](https://devforum.zoom.us/u/Ben_Cheeseman)\
**Post date:** [December 6, 2017, 4:24pm UTC](https://devforum.zoom.us/t/code-124-message-invalid-access-token-android-java/811/6 "2017-12-06T16:24:06Z")

</div>

We are using this library: jjwt - Java JWT: JSON Web Token for Java and Android

---

<div class="post-metadata">

**Author:** ![Ben\_Cheeseman](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@Ben\_Cheeseman](https://devforum.zoom.us/u/Ben_Cheeseman)\
**Post date:** [December 6, 2017, 4:55pm UTC](https://devforum.zoom.us/t/code-124-message-invalid-access-token-android-java/811/7 "2017-12-06T16:55:05Z")

</div>

This is how the token is passed&nbsp;

httpPost.addHeader(“Content-Type”, “application/x-www-form-urlencoded”);  
httpPost.addHeader(“Authorization: Bearer”, “eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMzAwODE5MzgwIiwiaXNzIjoiZUJjaFBUaElSOHEwMzBEdXR2REc5ZyJ9.G0HR9Psa6GTlItQHgt\_JgDqHIQaAsrH3HFNZ\_evA8Go”);  
httpPost.addHeader(“Content-Language”, “en-US”);

---

<div class="post-metadata">

**Author:** ![Joshua\_Woodward1](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/joshua_woodward1/32/1480_2.png) [@Joshua\_Woodward1](https://devforum.zoom.us/u/Joshua_Woodward1)\
**Post date:** [December 6, 2017, 4:59pm UTC](https://devforum.zoom.us/t/code-124-message-invalid-access-token-android-java/811/8 "2017-12-06T16:59:51Z")

</div>

There’s the issue

The key is “Authorization”, the value is “Bearer \<token\>”

So

httpPost.addHeader(“Authorization”, “Bearer \<token\>”);

---

<div class="post-metadata">

**Author:** ![Joshua\_Woodward1](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/joshua_woodward1/32/1480_2.png) [@Joshua\_Woodward1](https://devforum.zoom.us/u/Joshua_Woodward1)\
**Post date:** [December 6, 2017, 5:03pm UTC](https://devforum.zoom.us/t/code-124-message-invalid-access-token-android-java/811/9 "2017-12-06T17:03:50Z")

</div>

Also, depending on the endpoint, if it requires body arguments you should be using

httpPost.addHeader(“Content-Type”, “application/json”);

The data should be sent in the body as a json string/object (I believe only changing a user’s profile pic api is different, and that would be form data, not form url encoded)

&nbsp;

httpPost.addHeader(“Content-Language”, “en-US”); shouldn’t be necessary&nbsp;

---

<div class="post-metadata">

**Author:** ![Ben\_Cheeseman](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@Ben\_Cheeseman](https://devforum.zoom.us/u/Ben_Cheeseman)\
**Post date:** [December 6, 2017, 7:01pm UTC](https://devforum.zoom.us/t/code-124-message-invalid-access-token-android-java/811/10 "2017-12-06T19:01:45Z")

</div>

Hi Josh,

That did not seem to work, here is the entire thing:&nbsp;

&nbsp;

@Override  
protected String doInBackground(String… params) {  
HttpClient httpClient = new DefaultHttpClient();  
HttpPost httpPost = new HttpPost(“[https://api.zoom.us/v2/users](https://api.zoom.us/v2/users)”);  
List\<NameValuePair\> nameValuePair = new ArrayList\<NameValuePair\>(1);  
nameValuePair.add(new BasicNameValuePair(“api\_key”, Keys.API\_KEY));  
nameValuePair.add(new BasicNameValuePair(“api\_secret”, Keys.API\_SECRET));  
[//nameValuePair.add](https://nameValuePair.add)(new BasicNameValuePair(“Authorization: Bearer”, compactJws));  
nameValuePair.add(new BasicNameValuePair(“action”, “create”));  
nameValuePair.add(new BasicNameValuePair(“user\_info.email”, “[albert.charles@medrishealth.com](mailto:albert.charles@medrishealth.com)”));  
nameValuePair.add(new BasicNameValuePair(“user\_info.type”, “3”));  
nameValuePair.add(new BasicNameValuePair(“user\_info.first\_name”, “Albert”));  
nameValuePair.add(new BasicNameValuePair(“user\_info.last\_name”, “Charles”));  
nameValuePair.add(new BasicNameValuePair(“user\_info.password”, “Test123”));

try {  
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));  
httpPost.addHeader(“Content-Type”, “application/x-www-form-urlencoded”);  
[//httpPost.addHeader](https://httpPost.addHeader)(“Content-Type”, “application/json”);  
httpPost.addHeader(“Authorization”, “Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMzAwODE5MzgwIiwiaXNzIjoiZUJjaFBUaElSOHEwMzBEdXR2REc5ZyJ9.G0HR9Psa6GTlItQHgt\_JgDqHIQaAsrH3HFNZ\_evA8Go”);  
[//httpPost.addHeader](https://httpPost.addHeader)(“Content-Language”, “en-US”);  
HttpResponse httpResponse = httpClient.execute(httpPost);  
HttpEntity httpEntity = httpResponse.getEntity();  
String jsonStr = EntityUtils.toString(httpEntity);

if (jsonStr != null) {  
strServerStatus = “Success”;  
} else {  
strServerStatus = “Error”;  
}  
} catch (UnsupportedEncodingException e) {  
e.printStackTrace();  
strServerStatus = “UnsupportedEncodingException”;  
} catch (IOException e) {  
e.printStackTrace();  
strServerStatus = “IOException”;  
}  
return strServerStatus;  
}

---

<div class="post-metadata">

**Author:** ![Joshua\_Woodward1](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/joshua_woodward1/32/1480_2.png) [@Joshua\_Woodward1](https://devforum.zoom.us/u/Joshua_Woodward1)\
**Post date:** [December 6, 2017, 7:37pm UTC](https://devforum.zoom.us/t/code-124-message-invalid-access-token-android-java/811/11 "2017-12-06T19:37:43Z")

</div>

I’m not a Java expert, however there seems to be a red flag to me with&nbsp;httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair)); as mentioned before it should be a JSON, not a url encoded form.

In the end you should be passing something like&nbsp;{ “action”: “string”, “user\_info”: { “email”: “string”, “type”: “integer”, “first\_name”: “string”, “last\_name”: “string” } } in the body of the request

&nbsp;

take a look at&nbsp;[https://stackoverflow.com/questions/43690673/send-json-as-post](https://stackoverflow.com/questions/43690673/send-json-as-post) Your code would look something like

&nbsp;

JsonObject payload = new JsonObject();  
JsonObject user\_info = new JsonObject();

payload.addProperty(“action”, “create”);

user\_info.addProperty(“email”,“[albert.charles@medrishealth.com](mailto:albert.charles@medrishealth.com)”);  
user\_info.addProperty(“type”, 3); //integer&nbsp;data type  
user\_info.addProperty(“first\_name”, “Albert”);  
user\_info.addProperty(“last\_name”, “Charles”);  
//password is only used if action is autocreate

payload.addProperty(“user\_info”, user\_info); //not sure if this is really allowed, however user\_info an object

&nbsp;

RequestBody requestBody = RequestBody.create(jsonMediaType, new Gson().toJson(payload));

OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()  
.url(“[http://api.zoom.us/v2/users](http://api.zoom.us/v2/users)”)  
.post(requestBody)  
.addHeader(“content-type”, “application/json”)  
.build();

Response response = client.newCall(request).execute();

// this is the response of the post request  
String res = response.body().string();

// you can get the response as json like this  
JsonObject responseJson = new Gson().fromJson(res, JsonObject.class);

---

<div class="post-metadata">

**Author:** ![Joshua\_Woodward1](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/joshua_woodward1/32/1480_2.png) [@Joshua\_Woodward1](https://devforum.zoom.us/u/Joshua_Woodward1)\
**Post date:** [December 6, 2017, 7:39pm UTC](https://devforum.zoom.us/t/code-124-message-invalid-access-token-android-java/811/12 "2017-12-06T19:39:18Z")

</div>

Be sure to include the authorization header too

…

Request request = new Request.Builder()  
.url(“[http://api.zoom.us/v2/users](http://api.zoom.us/v2/users)”)  
.post(requestBody)  
.addHeader(“content-type”, “application/json”)  
**.addHeader(“Authorization”, “Bearer \<token\>”)**  
.build();

…

---

<div class="post-metadata">

**Author:** ![Ben\_Cheeseman](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@Ben\_Cheeseman](https://devforum.zoom.us/u/Ben_Cheeseman)\
**Post date:** [December 7, 2017, 2:49pm UTC](https://devforum.zoom.us/t/code-124-message-invalid-access-token-android-java/811/13 "2017-12-07T14:49:03Z")

</div>

This statement is throwing an exception:

&nbsp;

payload.addProperty(“user\_info”, user\_info.getAsString());

---

<div class="post-metadata">

**Author:** ![Joshua\_Woodward1](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/joshua_woodward1/32/1480_2.png) [@Joshua\_Woodward1](https://devforum.zoom.us/u/Joshua_Woodward1)\
**Post date:** [December 7, 2017, 7:37pm UTC](https://devforum.zoom.us/t/code-124-message-invalid-access-token-android-java/811/14 "2017-12-07T19:37:03Z")

</div>

What’s the exception?

Did you try just&nbsp;payload.addProperty(“user\_info”, user\_info);

---

<div class="post-metadata">

**Author:** ![DeveloperBot](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/developerbot/32/12632_2.png) [@DeveloperBot](https://devforum.zoom.us/u/DeveloperBot)\
**Post date:** [August 21, 2020, 5:21pm UTC](https://devforum.zoom.us/t/code-124-message-invalid-access-token-android-java/811/15 "2020-08-21T17:21:50Z")

</div>


