2
votes

I'm trying to list all the users in Jira using the REST API, I'm currently using the search user feature using GET : https://docs.atlassian.com/jira/REST/server/#api/2/user-findUsers

The thing is it says that the result will by default display the 50 first result and that we can expand that result up to 1000. Compared to other features available in the REST API, the pagination here is not specified. An example is the group member feature : https://docs.atlassian.com/jira/REST/server/#api/2/group-getUsersFromGroup

Thus I did a test and with my test Jira filled with 2 members, tried to get only one result and see if there was some sort of indication referring to the rest of my result. The response provided will only give the results and no ways to get to know if there was more thatn 1000 (or 1 in my example), it's maybe logical but in the case of an organization with more than 1000 members, listing all the users doing this : http://jira/rest/api/2/user/search?username=.&maxResults=1000&includeInactive=true will only give at most 1000 results.

I'm getting all the users no matter what their name are using . as the matching character.

Thanks for your help!

2

2 Answers

1
votes

What you can do, is to calculate manually the number of users.

Let's say you have 98 users in your system.

First search will give you 50 users. Now you have an array and you can get the length of that array which is 50.

Since you do not know if there are 50 or 51 users, you execute another search with the parameter &startAt=50.

This time the array length is 48 instead of 50 and you know that you've reached all the users in the system.

0
votes

From speaking to Atlassian support, it seems like the user/search endpoint has a bug where it will only ever return the first 1,000 results at most.

One possible other way to get all of the users in your JIRA instance is to use the Crowd API's /rest/usermanagement/1/search endpoint:

curl -X GET \
  'https://jira.url/rest/usermanagement/1/search?entity-type=user&start-index=0&max-results=1000&expand=user' \
  -H 'Accept: application/json' -u username:password

You'll need to create a new JIRA User Server entry to create Crowd credentials (the username:password parameter above) for your application to use in its REST API calls:

  • Go to User Management.
  • Select JIRA User Server.
  • Add an application.
  • Enter the application name and password that the application will use when accessing your JIRA server application.
  • Enter the IP address, addresses, or IP CIDR block of the application, and click Save.