okta-sdk-java icon indicating copy to clipboard operation
okta-sdk-java copied to clipboard

Help wanted : UserResourcesApi.listUserGroups pagination support

Open dshrestha2025 opened this issue 9 months ago • 4 comments

Using following code only provides first 200 user group membership

var userResourcesApi = new UserResourcesApi(client); var groups = userResourcesApi.listUserGroups(userId);

However, there are no clear instructions on how we can get paged results for this list

https://developer.okta.com/okta-sdk-java/apidocs/com/okta/sdk/resource/api/UserResourcesApi.html

The doc says additional headers but I am having hard time coming up with the parameters required to get paged list as we can do for listUsers api.

The issue https://github.com/okta/okta-sdk-java/issues/1286 says this was added to the code but how do we make use of it.

dshrestha2025 avatar Mar 18 '25 14:03 dshrestha2025

It appears that pagination wasn't properly migrated when this was done. https://github.com/okta/okta-sdk-java/issues/1594

dshrestha2025 avatar Mar 18 '25 15:03 dshrestha2025

Hi @dshrestha2025, thanks for reporting this. Have you tried using this - https://developer.okta.com/okta-sdk-java/13.0.2/apidocs/index.html?com/okta/sdk/resource/common/PagedList.html you can use asNext() to check if more results exist, and getNextPage() to fetch the next set of results.

prachi-okta avatar Mar 19 '25 05:03 prachi-okta

@prachi-okta UserResourcesApi.listUserGroups(userId) is not returning PagedList<>. How can I use asNext() for List<>? Also, this seems to be deprecated in latest version. Is it actually possible to paginate through User.ResourcesApi.listUserGroups? Can you provide me a sample code on how this can be done if possible?

dshrestha2025 avatar Mar 21 '25 22:03 dshrestha2025

@dshrestha2025 I'm not a dev here, but I ran into a similar issue with the SystemLogApi. I found that, while the wrapper methods only return the business object without pagination features (which should obviously be changed), the API also sets the last response's code and headers into a "thread-local" variable that you can retrieve using client.getResponseHeaders(). The link header is what you need, specifically the one with rel=next (see the raw Rest API docs for details), and you can extract the required after parameter from it.

Unfortunately upon closer inspection of your use case, listUserGroups has no after parameter! I mean the Java wrapper method, the API obviously does. This makes your use case entirely unsupported, and must be fixed. In the meantime though, since it is possible to make custom calls to the Okta API, you can also try to directly feed the rel=next link into that (and specify List<Group> as the result type, just like how the original wrapper does it).

ilonachan avatar Aug 14 '25 11:08 ilonachan