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

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

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.

目標

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.

リクエスト

"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"]'

出力

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

Update data

How to update a current value with a new one:

リクエスト

"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"]'

出力

$ ./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

参考

We suggest that you use the free "REST API Browser" add-on to familiarize more with Jira API:

最終更新日 2022 年 8 月 23 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.