11

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 Petrov
  • 4,669
  • 4
  • 28
  • 40
  • 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

6 Answers6

5

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
  • 59
  • 1
  • 3
  • 2
    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
  • 2
    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... – Shaamaan Sep 08 '20 at 08:57
5

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
  • 38,157
  • 20
  • 203
  • 266
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
  • 9,911
  • 10
  • 41
  • 55
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,010
  • 11
  • 22
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
  • 796
  • 1
  • 7
  • 12
0

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 ;)