How to bulk update users email addresses in JIRA using REST API
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
The content on this page relates to platforms which are not supported for JIRA. Consequently, Atlassian cannot guarantee to provide any support for it. Please be aware that this material is provided for your information only and using it is done so at your own risk.
Goal
Modify users information for a large number of users in JIRA
Information may be:
username
email
display name
Solution
Example:
Steps to bulk update email addresses using JIRA REST API. For API method reference see:
Get data
How to display a current value for a user.
Please note there's jqutility used to parse JSON output data.
Request
"get_email.sh" bash script:
1
2
3
4
5
6
7
8
9
#!/bin/sh
admin_user="admin"
admin_password="password"
user="tomd"
url="http://jira.domain.com/rest/api/2/user?username=${user}"
curl -s -u "${admin_user}:${admin_password}" ${url} | jq '.["emailAddress"]'
Output
1
2
$ ./get_email.sh
"tomd@domain.com"
Update data
How to update a current value with a new one:
Request
"update_email.sh" bash script:
1
2
3
4
5
6
7
8
9
10
11
#!/bin/sh
admin_user="admin"
admin_password="password"
user="tomd"
url="http://jira.domain.com/rest/api/2/user?username=${user}"
headers="Content-Type: application/json"
data='{ "name": "tomd", "emailAddress": "tomd@new-domain.com" }'
curl -s -X PUT -u "${admin_user}:${admin_password}" -H "${headers}" --data "${data} ${url} | jq '.["emailAddress"]'
Output
1
2
$ ./update_email.sh
"tomd@new-domain.com"
Bulk update
Sample source data (users.txt):
1
2
3
4
user1 user1@new-domain
user2 user2@new-domain
user3 user3@new-domain
(...)
Sample update script (update_email.sh):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/sh
admin_user="admin"
admin_password="password"
user="$1"
user_new_email="${2}"
url="http://jira.domain.com/rest/api/2/user?username=${user}"
headers="Content-Type: application/json"
data='{ "name": "'$user'", "emailAddress": "'${user_new_email}'" }'
curl -s -X PUT -u "${admin_user}:${admin_password}" -H "${headers}" --data "${data}" ${url} | jq '.["emailAddress"]'
Sample execution:
1
$ cat users.txt | xargs -n2 ./update_email.sh
References
We suggest that you use the free "REST API Browser" add-on to familiarize more with Jira API:
Was this helpful?