Export users from User Management API or Programatically
Asked by Anirudh:

Hello ,

Is there any way to export users (<https://support.atlassian.com/security-and-access-policies/docs/export-users-from-a-site/>) programmatically via API or any other way

Thanks


Answers:
author: Darryl Lee
body: Hi!

I tried Bob Swift's CLI command [getUserList](https://bobswift.atlassian.net/wiki/spaces/JCLI/pages/1066767525/getUserList), then compared the output to the Export from the Admin interface, and alas, it misses a lot. (API calls the CLI uses are down at the end of this answer.)

```
acli jira -a getUserList --outputFormat 999 --file cliusers.csv
```

The resulting CSV only contains these columns:

|------------|----------------|------------|------------------------|---------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|--------|-----------------------------------------------------------------------|--------------|
| User       | Key            | Name       | Email                  | Time Zone           | Avatar URL                                                                                                                                                  | Active | Groups                                                                | Account Type |
| Darryl Lee | 12345:12ab3c45 | Darryl Lee | darryl.lee@myemail.com | America/Los_Angeles | <https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/557058:55df3d50-d179-4d17-b747-bf1484246c4f/76f52fda-5bf0-4d68-acb5-c032a63e755a/48> | Yes    | administrators,jira-administrators,jira-developers,shift2,site-admins | atlassian    |

And it only contains ACTIVE or INVITED user accounts, whereas the export from the Admin interface includes SUSPENDED accounts. Additionally the CSV has many many more columns, and optionally creates a row for each Group/User, allowing for easier group sorting.

|-------------------------------|------------------------------|--------------------------|--------------|-------------------------|-------------|--------------|----------|--------------------------------------------------|----------------------------------------|-------------------------------------|---------------------------------------|-------------------------------------|-------------------------------------|---------------------------|------------------------|--------------------------|------------------------|
| Group id                      | Group name                   | User id                  | User name    | email                   | User status | Added to org | Org role | Last seen in Jira Service Management - boomaster | Last seen in Jira Software - boomaster | Last seen in Confluence - boomaster | Last seen in Team Central - boomaster | Last seen in Statuspage - boomaster | Jira Service Management - boomaster | Jira Software - boomaster | Confluence - boomaster | Team Central - boomaster | Statuspage - boomaster |
| 123456-b2b1-xxxx-1234-xxxxxxx | jira-servicemanagement-users | 12345678ec1234567a0fd743 | fb-jiratest3 | fb-jiratest3@darryl.com | Suspended   | 17-Nov-21    | None     | Never accessed                                   | Never accessed                         | Never accessed                      | Never accessed                        | Never accessed                      | User                                | User                      | None                   | None                     | None                   |

So, it kind of depends on what you need.

I used the --verbose flag on getUserList and was able to see the API commands that CLI uses. Basically it's getting a list of users, then iterating through each one to get their group memberships:

```
https://YOURHOST.atlassian.net/rest/api/latest/users?maxResults=1000&startAt=1000
https://YOURHOST.atlassian.net/rest/api/latest/user?accountId=user1id&expand=groups%2CapplicationRoles
https://YOURHOST.atlassian.net/rest/api/latest/user?accountId=user2id&expand=groups%2CapplicationRoles
https://YOURHOST.atlassian.net/rest/api/latest/user?accountId=user3id&expand=groups%2CapplicationRoles
```


Tags: cloud