How to bulk get list of Jira Users having their user keys

I want to get list of Jira Users, preferably in one operation, by Jira Java API. I have list of corresponding User Keys. Most important restriction is that API must work both in Jira 6 and Jira 7.

1 answer

1 accepted

This widget could not be displayed.
Alexey Matveev Community Champion Jan 02, 2018

Hello,

Try something like this

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.security.login.LoginManager

LoginManager loginManager = ComponentAccessor.getComponent(LoginManager.class);

Set<ApplicationUser> appUsers = ComponentAccessor.getUserManager().getAllUsers();

Thank you for your answer, however I would like to get only users that keys I have, in order to avoid situation of loading all Jira Users to obtain only fraction of them, e.g. 2000 of 20000.

Alexey Matveev Community Champion Jan 03, 2018

Filter the appUsers list as you wish. I do not think your Jira crashes if you get the full list first.

I will follow your advice. Last question: is there a way to get only active Jira Users?

Alexey Matveev Community Champion Jan 03, 2018

The problem is that you said you want a script for Jira 6 and Jira 7. In Jira 7 you can use UserSearchService which will let you filter users before retrieving them. I am not sure if UserSearchService will work for you Jira 6 version. That is why when you filter the appUsers list check if a user is active by isActive method of ApplicationUser class. If you want to try UserSearchService the code would look like that

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.bc.user.search.UserSearchService

import com.atlassian.jira.bc.user.search.UserSearchParamsdef userSearchService = ComponentAccessor.getComponent(UserSearchService.class);UserSearchParams userSearchParams = (new UserSearchParams.Builder()).allowEmptyQuery(true).includeActive(false).includeInactive(true).maxResults(100000).build();userSearchService.findUsers("", userSearchParams).each{ it-> log.error(it.getKey())}

But I am not sure if the code works for Jira 6.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted yesterday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

54 views 1 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you