How to get all users using Java API in Jira 10

Hi, does anyone found a way how to get all the users created under Jira instance using Java API?
I want to use not deprecated methods but I don’t think it is possible.
Following method is deprecated since Jira 7.x: UserManager (Atlassian Jira - Server 10.5.0 API)

So we used following in Jira 8:

UserSearchParams userSearchParams = UserSearchParams.builder(userManager.getTotalUserCount())
                .allowEmptyQuery(true)
                .includeActive(true)
                .includeInactive(true)
                .build();

return userSearchService.findUsers("", userSearchParams)

but it is not possible on Jira 10, because the results are limited to 100 but there is no pagination implemented.

I think there are still the cases in which we need to get all the users. In my case, I have user properties stored on user and need to analyze it. Without possibility to get all the users I will need to create my own active objects table and services with all the users.

Thank you

I also tried /rest/api/2/user/search endpoint but it looks like I am affected by https://jira.atlassian.com/browse/JRASERVER-78520 and https://jira.atlassian.com/browse/JRASERVER-78660
Did anyone find a workaround which is not about direct access to the Jira DB?

1 Like

At least with 11.0.0 and 10.13.3 (LTS) backported there is a new option with REST.

See https://jira.atlassian.com/browse/JRASERVER-78660
and https://developer.atlassian.com/server/jira/platform/rest/v11002/api-group-user/#api-api-2-user-list-get

Max results is 2000 but you have a new pagination:

With the first call to /rest/api/2/user/list

you get a cursor with the result given as nextCursor or as full url in nextPage like so:

/rest/api/2/user/list?cursor=&maxResults=2000

If no nextPage or nextCursor attribute in the result there are no more users to fetch.

Cheers,
Christian

1 Like

Hello @martin.bayer,
as far as i know, Jira requires using the UserSearchService to page through users rather than fetch them all at ones.

But you are limited. If you truly need every user, you must loop through the pages (because Jira 10 enforces limits).

If you really want “all users” there could run into an performance issue. To get all users you can use the UserManger-Function getAllUsers();

// @Deprecate
Collection<ApplicationUser> allApplicationUser = ComponentAccessor.getUserManager().getAllApplicationUsers();

Hopefully it helps :slight_smile:

Chears, Daniel
DaGraTo Solutions