Update username and email using REST API or the database
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
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
In some specific use cases, Users have to change the username format or change the email domain for all internal users in Jira.
There are a few methods to bulk update user information:
Before you begin:
You can only change the username and email information of Internal Users or users coming from a Delegated Directory (Internal with LDAP). User status of external users coming from Active Directory or LDAP directory must be managed on the LDAP side and synchronized over to Jira.
If you have a Delegated Directory, you have to edit the directory settings and uncheck the option Copy user on Login, this will allow Jira to update the user status locally. This setting can be enabled after disabling the users you need to disable.
1. Rest API:
Jira has a Rest API endpoint to edit user information api/2/user:
Sending a PUT to this endpoint can disable users in bulk, Eg sending a PUT with the following request body below can change two users: https://jira.base.url/jira/rest/api/2/user?username=test1&username=test
{
"name": "test2",
"emailAddress": "test2@newdomain.com"
}
{
"name": "test3",
"emailAddress": "test3@newdomain.com"
}
For additional information related to the REST user endpoint please visit the Jira REST API's Documentation
Bash command line:
You can interact with this endpoint using a pre-defined user list from the bash command line, this makes the usage of this endpoint more dynamic to bulk disabling users:
Requirements:
- You must have a list of users in a .txt file;
- Usernames from this list must be line separated and must be exact same username from cwd_user table.
- These users must be either internal users or from a Delegated directory;
- The delegated directory must be edited, and uncheck the option Copy user on Login
- You must execute the command from the bash command line from the same path the .txt file is located.
#!/bin/bash
while read -r first second third; do printf "%s\t %s\t %s\t %s\n" "$first" "$second" "$third" "$(curl -s -u admin:admin -X PUT --data '{"username": "'"$first"'", "emailAddress":"'"$second"'", "name":"'"$third"'"}' -H "Content-Type: application/json" http://localhost:8080/rest/api/2/user?username=${first})"; done < data.txt
The command above will be changing the email address and username of all users within the data.txt file in the following format:
oldusername newemail@newdomain.com newusername
oldusername1 newemail1@newdomain.com newusername1
2. Database Edit
Always back up your data before performing any modifications to the database. If possible, test any alter, insert, update, or delete SQL commands on a staging server first.
The steps outlined on this article are provided AS-IS. This means we've had reports of them working for some customers — under certain circumstances — yet are not officially supported, nor can we guarantee they'll work for your specific scenario.
You may follow through and validate them on your own non-prod environments prior to production or fall back to supported alternatives if they don't work out.
We also invite you to reach out to our Community for matters that fall beyond Atlassian's scope of support!
As with any database edit, you will want to:
- Stop Jira
- Back up the database
- Run the query
- Start Jira
There are a couple of things to note on the use of the following query:
- It will need to be modified such that a@a.com is replaced with your user's email address, and the username is replaced by your user's username within Jira.
- As with the API call, this can only be performed on users in an Internal Directory or users coming from a Delegated Directory (Internal with LDAP). This query is currently designed where
directory_id=1
. This means that this will make the change to a user in a directory in the first position in your User Directories. If the directory your user is to be modified is not in the first position, then you will need to change thedirectory_id=
value to indicate the appropriate numerical position of your directory - The lower_user_name in the app_user table should be changed to match the corresponding lower_user_name from the cwd_user table.
update cwd_user set email_address='a@a.com', lower_email_address='a@a.com' where lower_user_name='username' and directory_id=1;
## Make sure the change the lower_user_name from the app_user table to match with the cwd_user record:
update app_user set lower_user_name = 'new.username.from.cwd_user' where lower_user_name = 'old.username'
## Also make sure to update the child_name and lower_child_name from the cwd_membership to also match the cwd_user/app_user record:
update cwd_membership set child_name = 'new.username.from.cwd_user', lower_child_name = 'new.lower.username.from.cwd_user' where lower_child_name = 'old.username'
WARNING
It's HIGHLY recommended that you test these updates in a safe environment as these can break your Jira integrity!
In some cases, wrong updates will make your Jira unusable and only recoverable using a database backup.
3. Rest API using Python script:
The intent is to update and change the Jira Internal Directory username of 1000 users by executing this script. The only remaining unchanged username will be the one used to run the script. The idea is to speed up the massive username changes, especially in cases there are a lot of users that required updates. Please refer to How to change the username accounts of the Jira Internal Directory using Python script.
The content on the referred page relates to scripts that are supported; however, the content is out of the scope of our Atlassian Support Offerings. Consequently, Atlassian cannot guarantee support. Please be aware that this material is provided for your information only and you may use it at your own risk.