# java.io.IOException: Server returned HTTP response code: 400

**URL:** <https://devforum.zoom.us/t/java-io-ioexception-server-returned-http-response-code-400/46743>\
**Category:** API and Webhooks\
**Created:** [March 27, 2021, 6:23pm UTC](https://devforum.zoom.us/t/java-io-ioexception-server-returned-http-response-code-400/46743 "2021-03-27T18:23:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fritz.tester](https://avatars.discourse-cdn.com/v4/letter/f/35a633/32.png) [@fritz.tester](https://devforum.zoom.us/u/fritz.tester)\
**Post date:** [March 27, 2021, 6:23pm UTC](https://devforum.zoom.us/t/java-io-ioexception-server-returned-http-response-code-400/46743/1 "2021-03-27T18:23:51Z")

</div>

## Using this template helps us debug your issues more effectively 🙂

**Description**  
I have the apiKey and secret for a “user-managed OAuth2 app” and the permission “scope meeting:read” “meeting:write” and “user:read”.  
With this I can generate a token.  
However, for all the following actions I get the HTTP response code: 400  
e.g.: java.io.IOException: Server returned HTTP response code: 400 for URL: [https://api.zoom.us/v2/users/me](https://api.zoom.us/v2/users/me)

**Error**  
java.io.IOException: Server returned HTTP response code: 400 for URL: [https://api.zoom.us/v2/users/me](https://api.zoom.us/v2/users/me)

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

**Which Endpoint/s?**  
[https://api.zoom.us/v2/users/me](https://api.zoom.us/v2/users/me)

**How To Reproduce (If applicable)**  
public static String getZoomUserInfo(String zoomApiKey, String zoomApiSecret) throws OAuthSystemException, OAuthProblemException, IOException {  
String getUrl = “[https://api.zoom.us/v2/users/me](https://api.zoom.us/v2/users/me)”;  
URL url = new URL(getUrl);  
HttpURLConnection con = (HttpURLConnection) url.openConnection();  
con.setRequestMethod(“GET”);  
[//con.setRequestProperty](https://con.setRequestProperty)(“Content-Type”, “application/json”);  
con.setRequestProperty(“Authorization”, "Bearer " + OAuthTools.getZoomOAuthToken(zoomApiKey, zoomApiSecret));  
BufferedReader in = new BufferedReader(  
new InputStreamReader(con.getInputStream()));  
String inputLine;  
StringBuffer content = new StringBuffer();  
while ((inputLine = in.readLine()) != null) {  
content.append(inputLine);  
}  
in.close();  
System.out.println(content.toString());  
con.disconnect();  
return content.toString();

```
}
public static final String TOKEN_REQUEST_URL = "https://zoom.us/oauth/token";
   public static String getZoomOAuthToken(String clientID, String clientSecret) throws OAuthSystemException, OAuthProblemException {

	   OAuthClient client = new OAuthClient(new URLConnectionClient());

        OAuthClientRequest request =
                OAuthClientRequest.tokenLocation(TOKEN_REQUEST_URL)
                .setGrantType(GrantType.CLIENT_CREDENTIALS)
                .setClientId(clientID)
                .setClientSecret(clientSecret)
                .buildQueryMessage();
        
        OAuthJSONAccessTokenResponse oAUthResponse = client.accessToken(request, OAuthJSONAccessTokenResponse.class);
        if (oAUthResponse != null) {
        	System.out.println(oAUthResponse.getBody());
        }
        String token = oAUthResponse.getAccessToken();

		return token;
   }
```

---

<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:** [March 29, 2021, 8:20pm UTC](https://devforum.zoom.us/t/java-io-ioexception-server-returned-http-response-code-400/46743/2 "2021-03-29T20:20:09Z")

</div>

Hey @fritz.tester,

Thank you for reaching out to the Zoom Developer Forum. Are you able to share the response body you’re seeing with the 400 status code?

Thanks,  
Max

---

<div class="post-metadata">

**Author:** ![fritz.tester](https://avatars.discourse-cdn.com/v4/letter/f/35a633/32.png) [@fritz.tester](https://devforum.zoom.us/u/fritz.tester)\
**Post date:** [March 31, 2021, 6:06am UTC](https://devforum.zoom.us/t/java-io-ioexception-server-returned-http-response-code-400/46743/3 "2021-03-31T06:06:55Z")

</div>

Hey Max,

thanks for answering.  
The respose returns the following as an error stream, even though these credentials were used to generate the token previously:  
REsponseCode 400  
{“code”:200,“message”:“Invalid api key or secret.”}

Since I also have a long-lived token, I alternatively tried to get a refresh token. However, this already returns response code 400 when requesting the token.

TokenRequestBuilder builder = OAuthClientRequest  
.tokenLocation(Constant.TOKEN\_REQUEST\_URL)  
.setGrantType(GrantType.REFRESH\_TOKEN)  
.setClientId(clientID)  
.setClientSecret(clientSecret);  
builder = builder.setRefreshToken(refreshToken);  
OAuthClientRequest request = builder.buildQueryMessage();  
request.addHeader(“Accept”, “application/json”);  
request.addHeader(“Content-Type”, “application/json”);  
// request.addHeader(“Content-Type”, “application/x-www-form-urlencoded”);  
OAuthClient oauthClient = new OAuthClient(new URLConnectionClient());

OAuthJSONAccessTokenResponse oAUthResponse = oauthClient.accessToken(request, OAuthJSONAccessTokenResponse.class);

Am grateful for any help.  
Greetings  
Renate

---

<div class="post-metadata">

**Author:** ![fritz.tester](https://avatars.discourse-cdn.com/v4/letter/f/35a633/32.png) [@fritz.tester](https://devforum.zoom.us/u/fritz.tester)\
**Post date:** [March 31, 2021, 3:32pm UTC](https://devforum.zoom.us/t/java-io-ioexception-server-returned-http-response-code-400/46743/4 "2021-03-31T15:32:09Z")

</div>

I have solved the problem.  
The correct gant\_type for me was refresh\_token.  
The problem was that the refresh\_token can only be used once.  
With the access\_token you get a new refresh\_token that you have to use for the next access\_token.

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [April 5, 2021, 7:39pm UTC](https://devforum.zoom.us/t/java-io-ioexception-server-returned-http-response-code-400/46743/5 "2021-04-05T19:39:16Z")

</div>

Happy to hear you got the issue sorted out @fritz.tester ! 🙂

Let us know if we can help with anything else.

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/6/1/614bdd549b610bbaa46ff934617683a02bdaa03c.png) [@system](https://devforum.zoom.us/u/system)\
**Post date:** [May 6, 2021, 5:39am UTC](https://devforum.zoom.us/t/java-io-ioexception-server-returned-http-response-code-400/46743/6 "2021-05-06T05:39:37Z")

</div>

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