# Getting 400 error while hitting groups endpoint

**URL:** <https://devforum.okta.com/t/getting-400-error-while-hitting-groups-endpoint/18068>\
**Category:** API\
**Tags:** api, java\
**Created:** [November 15, 2021, 7:20pm UTC](https://devforum.okta.com/t/getting-400-error-while-hitting-groups-endpoint/18068 "2021-11-15T19:20:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![angeline.alex](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@angeline.alex](https://devforum.okta.com/u/angeline.alex)\
**Post date:** [November 15, 2021, 7:20pm UTC](https://devforum.okta.com/t/getting-400-error-while-hitting-groups-endpoint/18068/1 "2021-11-15T19:20:57Z")

</div>

I have created API token and recorded the value to use in the application. With that I can see all the group details in postman.

 ![image](https://global.discourse-cdn.com/oktadev/original/2X/2/222d0a5154b5621a4ae36cc1fac1a95ab0745da9.png)

But the same is not working with my java application and getting 400 error.

```auto
String oktaURL = "https://oktaservername.oktapreview.com/api/v1/groups";
URL url1 = new URL(oktaURL);
httpsClient = (HttpsURLConnection) url1.openConnection();
httpsClient.setRequestMethod("GET");
httpsClient.setRequestProperty("Accept","application/json");	
httpsClient.setRequestProperty("Content-Type","application/json");	
httpsClient.setRequestProperty("Authorization", "SSWS xxxxxxxxxxx");
httpsClient.setInstanceFollowRedirects(false);

log.info ("Send the GET request");
// Send post request
httpsClient.setDoOutput(true);

```

Please shed some light with this issue.

---

<div class="post-metadata">

**Author:** ![warren](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@warren](https://devforum.okta.com/u/warren)\
**Post date:** [November 15, 2021, 7:49pm UTC](https://devforum.okta.com/t/getting-400-error-while-hitting-groups-endpoint/18068/2 "2021-11-15T19:49:01Z")

</div>

I’m not very familiar with Java but what is the connection between `oktaUrl` and `url1`?

---

<div class="post-metadata">

**Author:** ![angeline.alex](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@angeline.alex](https://devforum.okta.com/u/angeline.alex)\
**Post date:** [November 15, 2021, 8:05pm UTC](https://devforum.okta.com/t/getting-400-error-while-hitting-groups-endpoint/18068/3 "2021-11-15T20:05:15Z")

</div>

Missed to add a line. Updated.

---

<div class="post-metadata">

**Author:** ![angeline.alex](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@angeline.alex](https://devforum.okta.com/u/angeline.alex)\
**Post date:** [November 20, 2021, 12:46am UTC](https://devforum.okta.com/t/getting-400-error-while-hitting-groups-endpoint/18068/4 "2021-11-20T00:46:28Z")

</div>

API call didn’t work for me unfortunately got 405/400 error. Using okta sdk solved the issue. There is a built in listGroups method helped.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/oktadev/original/1X/589c4c5f80de422d01f47cee7185a7fb8227835c.png) [@system](https://devforum.okta.com/u/system)\
**Post date:** [November 21, 2021, 12:46am UTC](https://devforum.okta.com/t/getting-400-error-while-hitting-groups-endpoint/18068/5 "2021-11-21T00:46:37Z")

</div>

Closed on November 21, 2021, 12:46am UTC

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