I need to get all JIRA users in list

Hi folks,

i have two doubts,

I need to get all JIRA users in list, i tried in server side following are my code, using findUsersAllowEmptyQuery

JiraServiceContext jiraServiceContext = new JiraServiceContextImpl(application);
		UserSearchService userSearchService = ComponentAccessor.getComponent(UserSearchService.class);
return userSearchService.findUsersAllowEmptyQuery(jiraServiceContext, "");

Here am getting user list with 1000 records but i have more then 5000 records, could you please any one help me to come out this problem. and i also try to set to set UserSearchParams maxResult=5000, using findUsers

JiraServiceContext jiraServiceContext = new JiraServiceContextImpl(application);
		UserSearchService userSearchService = ComponentAccessor.getComponent(UserSearchService.class);
return userSearchService.findUsers(jiraServiceContext, "search?username=jai&maxResults=500");

this code not giving any result.
i tried JIRA REST API also for find users

`

/rest/api/2/user/search

`

here also we have limitation to get 1000 record,

Thnak you,

Hi @saravanakumar17391,

For the REST API, based on Find users documentation, max result is 1000. You can utilize the startAt query parameter for pagination.

For the Java approach, try using UserSearchService#findUsers where UserSearchParams is passed. For UserSearchParams use the one that has maxResults parameter. As the document says,

Use null for unlimited results.

Do take necessary precaution with unlimited results though.

Hope this helps.
Ian

hi @iragudo,

Thank you very much for your response. i solved this problem as you said UserSearchParams.

i need one more help how we find the total number of JIRA user count.

i found userSearchParams.getMaxResults() i dont know how to use this method to count total number of users in my jira. could you please help me for solve this problem.

Thank you.

You’re welcome, @saravanakumar17391.

To get the total user count, you might want to try either of these two approaches:

  1. UserManager#getTotalUserCount; all users active or not.

  2. If you already used UserSearchService#findUsers to get a List of all the users, might as well use the list that you have and get the size. If you do not expect the number of users to change very often, you might want to consider caching the count value so as to not find all the users all the time just to get the count.

Cheers,
Ian

Hi @iragudo,

Thank you so much for your help. i need one more help, am using following code,

Blockquote
UserSearchService userSearchService = ComponentAccessor.getComponent(UserSearchService.class);
UserSearchParams userSearchParams = (new UserSearchParams.Builder()).allowEmptyQuery(true).includeActive(true).includeInactive(true).maxResults(200).build();

here i dont know how to set startAt could you please help me to come out this problem.

Thank you.