Get a list of all users using API for data center

Shroomy
Contributor
June 27, 2023

As described here you can get a full list of all users using:

GET /rest/api/3/users

However, this API version is only available for cloud users.

How can we get a list of all user (active and inactive) on Data Center Jira? It is quite unbelievable that among all the different API calls one can make, this is not one of them... 😲

3 answers

0 votes
Logan Govender
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 14, 2024

Heres a code snippet in C# that will fetch all jira users, with paging:

int startAt = 0;
bool isLastPage = false;
var maxResults = 1000;
var users = new List<JiraUser>();

while (!isLastPage)
{
var url = $"https://{yourjirabaseurl}/api/latest/user/search?username=.&maxResults={maxResults}&startAt={startAt}";

var request = new HttpRequestMessage(HttpMethod.Get, url);
foreach (var header in headers)
{
request.Headers.Add(header.Key, header.Value);
}

var response = await _httpClient.SendAsync(request);

if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
var responseContent = JsonConvert.DeserializeObject<List<JiraUser>>(content);
if (responseContent != null)
{
users.AddRange(responseContent);
startAt += maxResults;
isLastPage = responseContent.Count < maxResults;
}
else
{
isLastPage = true;
}
}
else
{
_logger.LogError($"Failed to fetch users: {response.StatusCode}");
break;
}
}

0 votes
Ola Fagbemiro
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 27, 2023

Can always use/try  /rest/api/latest/user/search?username=.&maxResults=1000

Shroomy
Contributor
June 28, 2023

Hi,

This assumes there is a maximum of 1000 users. If there is more they will be left out.

It is also not possible to ask for more than 1000 users.

Since there is no pagination for this API call, there is no way to retrieve the rest of the users.

Therefore this does not solve the problem. Thanks for the suggestion though. I did see the same solution being mentioned in the comments elsewhere.

0 votes
Tim Perrault
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 27, 2023

Hello @Shroomy 

 

You can try /rest/api/2/user/search?username=.

 

I used this ticket as reference

Shroomy
Contributor
June 28, 2023

This is basically the same answer as abow, only a bit shorter. Thanks.

Tim Perrault
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 28, 2023

You could always get a plugin like Better Excel. It let's you export an excel file of all users that you could then filter the data there.

Shroomy
Contributor
June 28, 2023

Sure. But the whole point of using an API is programmatic processing of real time data between systems.

Tim Perrault
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 28, 2023

I would suggest you add your vote to the ticket I linked then. At this time the API does not support your needs.

Suggest an answer

Log in or Sign up to answer