19

I'm trying to get all users from JIRA REST API. I need to save all users to my Database from my own java client. Is it possible to do that ?

If so how we going to do that?

Plamen G
  • 4,729
  • 4
  • 33
  • 44
  • There's a request on Atlassian.com to implement this feature: https://jira.atlassian.com/browse/JRA-29069. –  Oct 21 '15 at 21:59
  • You can use `Get-JiraUser -Username '%' -IncludeInactive -Credential $cred` from the PSJira library: https://github.com/replicaJunction/PSJira. / http://stackoverflow.com/a/42086207/361842. – JohnLBevan Feb 07 '17 at 12:18
  • 1
    Shockingly bad API – garryp Mar 30 '22 at 09:38

8 Answers8

10

At present time:

for Jira Cloud:

to get all (active + inactive) users:

GET /rest/api/2/users/search?query

to get all active users:

GET /rest/api/2/user/search?query

    

for Jira Server:

to get all (active + inactive) users:

GET /rest/api/2/user/search?username=.&includeInactive=true

to get all active users:

GET /rest/api/2/user/search?username=.
Grygorii
  • 162
  • 2
  • 6
  • 5
    By default Jira returns only 50 items. To get more, `maxResults` can be used. For example `GET /rest/api/2/user/search?username=.&maxResults=1000`. – ks1322 Nov 01 '22 at 11:19
6

There seems to be an undocumented way:

Use the "Find user" api

https://docs.atlassian.com/jira/REST/latest/#api/2/user-findUsers

For the username query use %

EG: /rest/api/2/user/search?username=%

mattrq
  • 69
  • 1
  • 3
  • 3
    This does not work for me, using JIRA v6.4.3; perhaps it does in 7.0+? Querying `.../rest/api/2/user/search?username=e`, for example, returns several results, but `.../rest/api/2/user/search?username=%` or `...=%25` returns nothing. –  Oct 21 '15 at 22:01
  • 6
    Try `/user/search` with param `username` = `.` instead. Eg. `/rest/api/2/user/search?username=.&includeActive=true&includeInactive=false` to get all active users. – Datz Mar 19 '19 at 06:34
  • But how to get inactive users? Parameter includeInactive is deprecated in APi v3. – Romick Apr 23 '19 at 13:34
  • This will fail if there are more than 1000 results. Well, it won't "fail", but you'll never get more than 1000, even with the "startAt" param... – MBender Sep 08 '20 at 08:57
6

You can get all users that are assignable to a specific project. If everyone is assignable you will get all users.

/rest/api/2/user/assignable/search?project=PROJECT

Curl:

curl -D -u USERNAME:PASSWORD -X GET -H "Content-Type: application/json" https://company.atlassian.net/rest/api/2/user/assignable/search?project=PROJECT
Ogglas
  • 62,132
  • 37
  • 328
  • 418
1

One possible 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

Do note that 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.
Adil B
  • 14,635
  • 11
  • 60
  • 78
1

This worked for me:

https://company_name.altassian.net/rest/api/3/users/search?

It will return something like this:

[
{
    "accountId": "id",
    "accountType": "app",
    "avatarUrls": {},
    "displayName": "Slack",
    "active": true
},
{
    "self": "profile_link of ther user",
    "accountId": "id",
    "accountType": "atlassian",
    "avatarUrls": {},
    "displayName": "**Real user**",
    "active": true,
    "locale": "en_US"
}
]

Before saving to DB you'll have to check the accountType:

if (accountType == 'altassian') {
      then do push; // or whatever
}
Farhan
  • 1,445
  • 16
  • 24
1

I know it's an old thread but if anyone is searching for this now, this works for me at the moment:

GET /rest/api/latest/user/search?query=+&maxResults=1000

Thanks ;)

0

There is no direct method to get all users in Jira Rest API. You might have to use Search function(Which requires passing in atleast one letter to search) or Groups functions, if you have users readily grouped in Jira application.

Go through their documentation for better reference.

https://docs.atlassian.com/jira/REST/latest/#d2e2

https://docs.atlassian.com/jira/REST/latest/#d2e808

You can use simple JDBC scripts to some advanced ones for writing users list to database, through your java client.

Hope this helps!

Kishore Banala
  • 946
  • 1
  • 8
  • 12
-1

I also suffered with this problem for a long time. I had a task search by project completed tasks by user. Answer: https://developer.atlassian.com/rest/api/2/search?jql = project = yourProject + AND + status = done + AND + assignee= yourUser

  • Page not found error when clicking on the link that you have provided in your answer. – Subhashis Pandey Oct 29 '21 at 14:04
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/30210691) – Neea Oct 30 '21 at 04:52
  • This doesn't answer the OP's question - You can't formulate a JQL query that will return a list of users without writing a [custom function](https://developer.atlassian.com/server/jira/platform/role-members-jql-function-tutorial/). – Bill Horvath Jun 08 '23 at 21:00