How to bulk update users email addresses in JIRA using REST API

Still need help?

The Atlassian Community is here for you.

Ask the community

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 jq utility used to parse JSON output data.

Request

"get_email.sh" bash script:

#!/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

$ ./get_email.sh
"tomd@domain.com"

Update data

How to update a current value with a new one:

Request

"update_email.sh" bash script:

#!/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

$ ./update_email.sh
"tomd@new-domain.com"

Bulk update

Sample source data (users.txt):

user1   user1@new-domain
user2   user2@new-domain
user3   user3@new-domain
(...)

Sample update script (update_email.sh):

#!/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:

$ 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:

Last modified on Aug 23, 2022

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.