Get all jira users with AP

Hi, community.
Is it possible to get access to all Jira users by using AP? For example:
AP.request('/rest/api/3/users/search?startAt=0&maxResults=20')
I see a bunch of questions related to getting all users, but most of them is outdated. Right now I’m still using this endpoint to get users:
AP.request('/rest/api/3/user/search?query=&startAt=0&maxResults=20')
But, unfortunately it returns not all users for some reason.

Also, I saw Apps cannot access this REST resource message related to /rest/api/3/users/search. Some people say that it means you cannot access this endpoint by Atlassian Connect application. Other people say that this isn’t correct and you can access it. While using JWT or AP request I have 403 response result. It means that ‘I have no enough permission’(due docs), but this’s not correct cause I granted all possible permissions as administrator.

What’s the real point around it? It seems unusual to see endpoint in docs that is not accessible.

Kindest regards, Igor

1 Like

If I got it right, /rest/api/3/users/search is used only for strict connection to the Jira instance.
At the same time /rest/api/3/user/search is not supported for getting all users.

Appreciate any help with clarifying this.
Kindest regards, Igor

Hi,

  • You can fetch all users using GET rest/api/3/user/search?query=. If you call it with AP.request(), the logged in user must be in the group which has “Browse users and groups” permissions.
  • You can also make this API call from backend via JWT. Please make sure your app request ADMIN scope in descriptor. The only reason this might not work is if the Jira administrator decided to manually remove the hidden/system group atlassian-addons-admin from the global permission for Browse Users and Groups.

Cheers.

Hi @aagrawal2. Thank you for your answer!

I’m using this query in our logic. As I know the current max limit is 1000 users per request. That’s not an issue, I’m working with this limit and that’s fine for me. But our clients swear that they get only 900 users(that’s less than 1000) instead of 3000. Is there any possibility that some groups are hidden from the GET rest/api/3/user/search?query= endpoint?

Regards, Igor

If I got it right, /rest/api/3/users/search is used only for strict connection to the Jira instance.
At the same time /rest/api/3/user/search is not supported for getting all users.

^ You got these right.

The behaviour you mentioned is expected. As per GET /rest/api/3/user/search docs:

This operation takes the users in the range defined by startAt and maxResults , up to the thousandth user, and then returns only the users from that range that match the search string and property. This means the operation usually returns fewer users than specified in maxResults . To get a larger number of users, use Get all users and filter the records in your code.

For your use case, you should use GET /rest/api/3/users/search to get all users.

Cheers.

@aagrawal2, thank you for clarification! It’s very important for me. I see that I need to use GET /rest/api/3/users/search to get all users, but is there any possibility to use this endpoint inside Atlassian Connect Add-on?

I’m concerned about “Apps cannot access this REST resource” message and the fact that it’s not working like any other endpoint that I’m using(while using JWT or AP request I have 403 response result). I want to clarify, is it happening because I’m doing something wrong.

Is it possible to use GET /rest/api/3/users/search endpoint inside Cloud Addon? If not, does it mean that there is no way to get all users from inside of Cloud Addon?

Regards, Igor

@piskunovigorm Could you please explain your use case for which you are trying to get all users?

@aagrawal2, sure! Our add-on is a CRM component that contains different tabs. One of these tabs is the “contacts” tab that stores any information that the client needs. The client is interested to connect this information with specific Jira User and in order to fill the table with all Jira users automatically, he needs(I/we need) access to all Jira users once. So this “contacts” list will be automatically created based on Jira Users list if the client wants.

For this feature, we need just accountId and displayName(by user permission).

We tried to implement this functionality through GET rest/api/3/user/search?query= endpoint. But it doesn’t work for big instances with more than 1000 users. And our clients informed us about that immediately.

One of the options that we have: to fill the table with Jira Users manually. But that will decrease the client’s speed and affects productivity. So we’re looking for any workaround to make their life a little bit easier.

Regards, Igor

@piskunovigorm
I discussed this with our team and we recommend to rethink your implementation. Looking through hundreds or thousands of results is tedious for end user. So instead, only render the first n results (or none at all). If you want more than n results, a search is required. When you search, we will filter the results down to matching users in order of relevance which will make the process of finding a user easier.

In your current approach, there maybe risk of API returning unsorted results, could be poor performing and storing this data may put you you at risk of GDPR violations.

Cheers.

@aagrawal2
You’re suggesting not to try to get all users list and synchronize it with our database. Instead of that, we should implement an approach that will use only partial search. Am I right? Just want to clarify.

Regards, Igor

Yes, that’s correct :slight_smile:

@aagrawal2, thank you for clarification!