JohnLBevan JohnLBevan - 1 month ago 13
reST (reStructuredText) Question

Get a list of users from Atlassian's Cloud / On-Demand Service

I'm trying to pull a list of users from our Atlassian Confluence/Jira instance. However I'm struggling to find good documentation on what REST services are available, and it seems the SOAP services are deprecated.

The following code does get results, but we have over 100 users, and this returns 0.

if(-not ($credentials)) { #put this here so I can rerun the same script in the same IDE session without having to reinput credentials each time
$credentials = get-credential 'myAtlassianUsername'
}
$tenant = 'myCompany'
invoke-restmethod -Method Get -Uri ('https://{0}.atlassian.net/rest/api/2/groupuserpicker?query=users' -f $tenant) -Credential $credentials | ConvertTo-Json -Depth 5


(The
ConvertTo-Json
is just to make it simpler to see the expanded result set).

{
"users": {
"users": [

],
"total": 0,
"header": "Showing 0 of 0 matching users"
},
"groups": {
"header": "Showing 2 of 2 matching groups",
"total": 2,
"groups": [
{
"name": "confluence-users",
"html": "confluence-\u003cb\u003eusers\u003c/b\u003e",
"labels": [

]
},
{
"name": "jira-users",
"html": "jira-\u003cb\u003eusers\u003c/b\u003e",
"labels": [

]
}
]
}
}


I think the result's trying to give me the URLs for the JIRA and Confluence User APIs; but I can't figure out how those relative URLs map to the root URL (I've tried appending at various positions in the URL, all of which give me a
404
or
dead link
error).

Answer

The query parameter in your following call is a search query on the Name or E-mail address. Reference: https://docs.atlassian.com/jira/REST/cloud/#api/2/groupuserpicker.

You can use maxResults parameter to get more than 50 results.

Sadly, his REST API call will not give you all users in one call.

The only way that I know to do with Jira to get all users is to make one call by starting letter (iterate on each letter):

GET .../rest/api/2/user/search?username=a&maxResults=1000
GET .../rest/api/2/user/search?username=b&maxResults=1000
GET .../rest/api/2/user/search?username=c&maxResults=1000
...

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