# Fetching Groups assigned to a Application using Java SDK

**URL:** <https://devforum.okta.com/t/fetching-groups-assigned-to-a-application-using-java-sdk/15289>\
**Category:** Questions\
**Created:** [July 27, 2021, 12:34pm UTC](https://devforum.okta.com/t/fetching-groups-assigned-to-a-application-using-java-sdk/15289 "2021-07-27T12:34:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sureshponnada](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@sureshponnada](https://devforum.okta.com/u/sureshponnada)\
**Post date:** [July 27, 2021, 12:34pm UTC](https://devforum.okta.com/t/fetching-groups-assigned-to-a-application-using-java-sdk/15289/1 "2021-07-27T12:34:02Z")

</div>

Hi,  
I’m trying to get a list of Groups assigned to a Application from Java SDK and using below code.  
String search=“source.id%20eq%20%220oa3mgdp2XRMOLJYv1d6%22”;  
GroupList grpList = client.listGroups(null, search, null);

But Im gettting below error:  
"HTTP 400, Okta E0000031 (Invalid search criteria.), ErrorId oaevpxB3-xuRJyQ1c8-rgIpKQException in thread “main”  
com.okta.sdk.resource.ResourceException: HTTP 400, Okta E0000031 (Invalid search criteria.), ErrorId oaevpxB3-xuRJyQ1c8-rgIpKQ

In source.id I’m passing the Application id. I have seen few examples using REST API but not from java api.  
Could you please provide few examples how the parameters “q”, “search”, “expand” needs to be formed for this method.

Client. `listGroups(java.lang.String q, java.lang.String search, java.lang.String expand)`

Thanks & Regards  
Suresh

---

<div class="post-metadata">

**Author:** ![Lijia](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/lijia/32/2295_2.png) [@Lijia](https://devforum.okta.com/u/Lijia)\
**Post date:** [July 27, 2021, 7:49pm UTC](https://devforum.okta.com/t/fetching-groups-assigned-to-a-application-using-java-sdk/15289/2 "2021-07-27T19:49:48Z")

</div>

@sureshponnada Hi, Please refer the API doc [here] ([Groups | Okta Developer](https://developer.okta.com/docs/reference/api/groups/#list-groups)). It contains examples of list group with filter. I suggest you can test in postman first before running it through codes.

---

<div class="post-metadata">

**Author:** ![sureshponnada](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@sureshponnada](https://devforum.okta.com/u/sureshponnada)\
**Post date:** [July 28, 2021, 7:00am UTC](https://devforum.okta.com/t/fetching-groups-assigned-to-a-application-using-java-sdk/15289/3 "2021-07-28T07:00:51Z")

</div>

Hi Lijia, Thanks for your response. I’ve referred those examples meant for REST API. I’m working on migration project so developing my scripts in Okta java sdk.  
e.g. in REST API below search will work:  
“https://${yourOktaDomain}/api/v1/groups?filter=type+eq+“OKTA\_GROUP”&limit=200”

same I need to pass to Client.listGroups(String q, String filter, String expand)  
so I’ve formed filter string in few combinations provided below but nothing is working.  
String filter =“type%20eq%20%22OKTA\_GROUP%22”;  
String filter =“type+eq+“OKTA\_GROUP””;  
String filter =“filter=type+eq+“OKTA\_GROUP””;

Here I’m passing Type = Okta\_group withURL encoded as mentioned in the documentation.  
If i pass all nulls in Client.listGroups(null, null, null) I’m getting the results. so Issue is only in the way I’m passing “filter”.

---

<div class="post-metadata">

**Author:** ![sureshponnada](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@sureshponnada](https://devforum.okta.com/u/sureshponnada)\
**Post date:** [July 28, 2021, 3:58pm UTC](https://devforum.okta.com/t/fetching-groups-assigned-to-a-application-using-java-sdk/15289/4 "2021-07-28T15:58:52Z")

</div>

This is now resolved after i passed the below filter. It looks like i don’t need to do URLEncoded for the parameter.

```auto
 String search ="type eq \"OKTA_GROUP\"";

```

Thanks & Regards  
Suresh

---

<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:** [July 29, 2021, 3:59pm UTC](https://devforum.okta.com/t/fetching-groups-assigned-to-a-application-using-java-sdk/15289/5 "2021-07-29T15:59:33Z")

</div>

Closed on July 29, 2021, 3:59pm UTC

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