# 405 error for while hitting /groups endpoint for the user

**URL:** <https://devforum.okta.com/t/405-error-for-while-hitting-groups-endpoint-for-the-user/18071>\
**Category:** API\
**Tags:** api, java\
**Created:** [November 15, 2021, 11:13pm UTC](https://devforum.okta.com/t/405-error-for-while-hitting-groups-endpoint-for-the-user/18071 "2021-11-15T23:13:35Z")\
**Posts on this page:** 8\
**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, 11:13pm UTC](https://devforum.okta.com/t/405-error-for-while-hitting-groups-endpoint-for-the-user/18071/1 "2021-11-15T23:13:36Z")

</div>

I am trying to hit the below endpoint and getting **405** error… got the userid from /userinfo  
[https://XXX.oktapreview.com/api/v1/users/userid/groups](https://XXX.oktapreview.com/api/v1/users/userid/groups)

But this URL works fine in postman and giving me the list of groups assigned to the user. but in java code its giving 405.

```auto
URL url1 = new URL(oktaURL);
httpsClient = (HttpsURLConnection) url1.openConnection();
httpsClient.setRequestMethod("GET");
httpsClient.setRequestProperty("Content-Type","application/json");	
httpsClient.setRequestProperty("Authorization", "SSWS " + apiToken);

```

Please help…

---

<div class="post-metadata">

**Author:** ![Cale](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/cale/32/2496_2.png) [@Cale](https://devforum.okta.com/u/Cale)\
**Post date:** [November 16, 2021, 2:00pm UTC](https://devforum.okta.com/t/405-error-for-while-hitting-groups-endpoint-for-the-user/18071/2 "2021-11-16T14:00:05Z")

</div>

405 errors indicate you’re using the wrong HTTP verb. GET is correct…any chance it was another verb at some point and you need to re-compile?

---

<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 16, 2021, 6:55pm UTC](https://devforum.okta.com/t/405-error-for-while-hitting-groups-endpoint-for-the-user/18071/3 "2021-11-16T18:55:50Z")

</div>

I am not really sure about that. I did restart my system and also eclipse… it didnt not help.

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [November 19, 2021, 5:52pm UTC](https://devforum.okta.com/t/405-error-for-while-hitting-groups-endpoint-for-the-user/18071/4 "2021-11-19T17:52:35Z")

</div>

Have you tried using our [Java Management SDK](https://github.com/okta/okta-sdk-java)? It has a built in [listGroups method](https://developer.okta.com/okta-sdk-java/apidocs/com/okta/sdk/resource/user/User.html#listGroups--) you can use to make this call for you.

---

<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 19, 2021, 9:53pm UTC](https://devforum.okta.com/t/405-error-for-while-hitting-groups-endpoint-for-the-user/18071/5 "2021-11-19T21:53:35Z")

</div>

Thanks Andrea, this worked for me and I am able to get the groups with java SDK. Thank you.

One follow up question on this.  
How to get the users list from the groups?

I tried listUsers method… this lists all the users from all the groups. I am looking for some way to get only users on a particular group in the SDK.

Please advice.

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [November 19, 2021, 9:58pm UTC](https://devforum.okta.com/t/405-error-for-while-hitting-groups-endpoint-for-the-user/18071/6 "2021-11-19T21:58:43Z")

</div>

There’s a [listUsers](https://developer.okta.com/okta-sdk-java/apidocs/com/okta/sdk/resource/group/Group.html#listUsers--) method you can use on a Group that should work

---

<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 19, 2021, 10:05pm UTC](https://devforum.okta.com/t/405-error-for-while-hitting-groups-endpoint-for-the-user/18071/7 "2021-11-19T22:05:57Z")

</div>

This worked great. Thanks Andrea.

---

<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 20, 2021, 10:06pm UTC](https://devforum.okta.com/t/405-error-for-while-hitting-groups-endpoint-for-the-user/18071/8 "2021-11-20T22:06:51Z")

</div>

Closed on November 20, 2021, 10:06pm UTC

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