When I imported a redmine project into jira, all the the redmine project users were unexpectedly created in our jira instance. I now need to delete 100+ users. Can I mass delete these new users somehow?
Thanks!
Yen
Hi Yen,
It would be safer to use JIRA Command Line Interface removeUser action. UserunFromSql to do it in bulk. Doing database actions directly is error prone and you need to understand all the application's database structure. The dangers of doing direct database actions have been commented on numerously on this site.
Hope it helps.
Monique
Thanks Monique - I did see this answer but I was hoping there was an option within the ondemand instance where I can just check box names and delete them.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Write a little js code as follows and run it in Chrome after logging into the Admin console.
var baseURL = "https://mycompany.atlassian.net//admin/rest/um/1/user?username=";
function deleteUser(userId) {
var xhttp = new XMLHttpRequest();
xhttp.open("DELETE", baseURL+userId, true);
xhttp.send();
console.log(responseText);
}
function bulkDelete() {
var usersToDelete = ["user1", "user2", "user3"];
for (var i=0; i< usersToDelete.length; i++) {
deleteUser(usersToDelete[i];
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for this - very handy script.
Small correction - you're missing the close bracket on the last line of code (the deleteUser() call).
deleteUser(usersToDelete[i]);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When I attempt this I get a "undefined" error on line 1. I even attempted to not wrap the baseURL into a variable and place it directly in the function and I still get an "undefined" error on line 1 :/
UPDATE: I just needed to add "bulkDelete();" to the snippet. Also there was an issue with the "responseText". I was able to rewrite it and now works as expected:
var baseURL = "https://mycompany.atlassian.net/admin/rest/um/1/user?username=";
function deleteUser(userId) {
console.log('Deleting '+userId);
return fetch(baseURL+userId, {
method: 'DELETE',
credentials: 'same-origin',
})
.then(res => console.log(res, res.text()))
.catch(function(error) {
console.log('There has been a problem with your fetch operation: ', error.message);
});
}
function bulkDelete() {
var usersToDelete = [
"user1",
"user2",
"etc"
];
for (var i=0; i< usersToDelete.length; i++) {
deleteUser(usersToDelete[i]);
}
}
bulkDelete();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here's a working version:
var baseURL = 'https://yourcompany.atlassian.net/admin/rest/um/1/user?username=';
var usersToDelete = ['person@company.com', 'bob@company.com'];
function deleteUser(userId) {
console.log('Deleting ' + userId);
return fetch(baseURL + userId, {
method: 'DELETE',
credentials: 'same-origin'
})
.then(res => console.log(res, res.text()))
.catch(function(error) {
console.log('There has been a problem with your fetch operation: ', error.message);
});
}
Promise.all(usersToDelete.map(deleteUser)).then(_ => console.log('All done!'));
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This last version worked for me in atlassian cloud, however I had to use the built in name for the users, not the email (in my case, the first part of the email, before the '@') eg. user.name
Secondly, just confirming that the base URL must match your site eg. 'https://yourcompany.atlassian.net/...', and not the admin site 'https://admin.atlassian.com/...'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How did it work for you? I tried it in firefox and chrome and got a revoked error due to cloud not allowing anonymized access.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Using the Rest API 3, tokens, and snippets:
1. HAVE PERMISSION: Ensure you're in the site-admin group.
2. CREATE TOKEN: Go to your profile, which is clicking on your portrait in lower left; select edit profile; go to security. Under API token, click create and manage. Give your token a snarky name, then copy the value that comes back. WARNING: This is the only opportunity you will have to get its value.
3. GET USER IDS TO DELETE: In your /secure/BrowseProjects.jspa, under the menu for Jira Software, go to Jira Settings. Near the bottom, go to User Management. This will redirect you to admin.atlassian.com/s/yourbusinessid/users. Click export users, select them all. Open the file in excel and filter as you wish. The left-most column is the user ID. You can then multiline edit with Alt-Shift in VS or ctrl-alt in VSCode, to add the "", to each ID.
4. RUN SNIPPET: Back on your company page (not the admin.atlassian.com). Open Chrome Dev Tools (inspect) Go to the sources tab. If you don't see snippets, click the >> to open a new menu, click snippets. Add a new snippet. (To run it, click the play button at bottom of window.)
var baseURL = "https://yourcompany.atlassian.net/rest/api/3/user?accountId=";
function deleteUser(userId) {
console.log('Deleting '+userId);
return fetch(baseURL+userId, {
method: 'DELETE',
headers: {
'Authorization': `Basic ` + btoa('you@youremail.com:secrettokencode')
}
})
.then(res => console.log(res, res.text()))
.catch(function(error) {
console.log('There has been a problem with your fetch operation: ', error.message);
});
}
function bulkDelete() {
var usersToDelete = [
"userid1",
"userid2etc"
];
for (var i=0; i< usersToDelete.length; i++) {
deleteUser(usersToDelete[i]);
}
}
bulkDelete();
Thank you to the users who provided the original code, these are the updates in May of 2020.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This script worked for me, thank you! However I was only able to delete about 100 users at a time (out of many thousands). I kept re-running the script every min or so without changing the list of usersToDelete.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If someone else runs into this issue, just a reminder you could do a for loop with a timeout...
example:
for (var x=0; x < 100; x++){
setTimeout(function(){
bulkDelete();
}, 60000);
}
And no, even though I could upvote my own post with this alt account, I didn't.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is a Jira cloud addon developed by my company that allows you to search, filter and bulk delete users:
https://marketplace.atlassian.com/apps/1221764/user-management-by-toros
In addition, it allows you to search for inactive users (users who haven't login in a while) and perform some bulk operation.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
it keeps on giving me errors
1/1 actions have failed with the following errors:{"errorMessages":[],"errors":{}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Workaround: Install this add-on https://chrome.google.com/webstore/detail/uivision-kantu-for-chrome/gcbalfbdmfieckjlnblleoemohcganoc in Google chrome browser. Do some excel tricks and generate the user profile URL for all the users to be off-boarded. (You can find ID for each user when you export users) Understand the JSON structure of the kantu add-on and generate JSON for the operations bringBrowsertoFront (opens google chrome browser), open (opens the URL supplied in JSON, click(clicks the toggle button in the user profile page). Tada !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There is a plugin called "Bulk User Delete for Jira" that will do it.
https://marketplace.atlassian.com/plugins/com.empyra.bud.BulkUserDeleteforJira/server/overview
The plugin has cloud and server version.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There is a plugin called "Bulk User Delete for Jira" that will do it.
https://marketplace.atlassian.com/plugins/com.empyra.bud.BulkUserDeleteforJira/server/overview
You just won't be able to delete administrators in bulk. It only works for non-admin users.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Unfortunately this plugin does not work more faster than deleting users via user interface
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
tried it but it doesn't see deactivated users.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I wrote a little bash script which accepts a file with a list of usernames, then runs curl to call the API to delete each user.
Usage:
$ cat foo
ninja
$ ./jiracmd-user-delete foo
Jira Base URL:https://jira.uwo.ca
Username:aculver
Password:
ninja: {"errorMessages":["Cannot delete user 'ninja' because 12 issues were reported by this person.","Cannot delete user 'ninja' because they have made 11 comments."],"errors":{}}
If the delete was successful, you'll see a line reading "username:"
If the delete failed, you'll see "username: {json containing error message}"
Script:
#!/bin/bash
# CONFIG
# Give these values to skip prompts
adminuser=
jira=
# END CONFIG
if [ $# -ne 1 ]; then
echo "Usage: $0 infile"
exit 1
fi
infile=$1
if [ ! -r $infile ]; then
echo "Can't read file: $infile"
exit 1
fi
if [ -z $jira ]; then
echo -n "Jira Base URL:"
read jira
fi
if [ -z $adminuser ]; then
echo -n "Username:"
read adminuser
fi
echo -n "Password:"
read -s adminpass
echo
cmd=DELETE
api=/rest/api/2/user
while read u; do
echo -n "$u: "
curl --insecure --silent --show-error -u $adminuser:$adminpass -X $cmd -H "Content-Type: application/json" "$jira$api?username=$u"
echo
done < $infile
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Andrew.
Does your script work with Atlassian Cloud?
Thanks.
BR,
Vitalii
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I know I'm a little late but you could also explore using Jelly scripts.
https://confluence.atlassian.com/display/JIRA/Jelly+Tags#JellyTags-jira:RemoveUser
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh and it is FREE
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Another possible alternative to delete users programatically is writing a script and using the JIRA REST API:
The feature request raised for bulk user delete operations in JIRA is https://jira.atlassian.com/browse/JRA-8047, and you may vote on it to increase its visibility with our developers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When I attempt this I get a "undefined" error on line 1. I even attempted to not wrap the baseURL into a variable and place it directly in the function and I still get an "undefined" error on line 1 :/
UPDATE: I just needed to add "bulkDelete();" to the snippet. Also there was an issue with the "responseText". I was able to rewrite it and now works as expected:
var baseURL = "https://mycompany.atlassian.net/admin/rest/um/1/user?username=";
function deleteUser(userId) {
console.log('Deleting '+userId);
return fetch(baseURL+userId, {
method: 'DELETE',
credentials: 'same-origin',
})
.then(res => console.log(res, res.text()))
.catch(function(error) {
console.log('There has been a problem with your fetch operation: ', error.message);
});
}
function bulkDelete() {
var usersToDelete = [
"user1",
"user2",
"etc"
];
for (var i=0; i< usersToDelete.length; i++) {
deleteUser(usersToDelete[i]);
}
}
bulkDelete();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
16 years request and still under consideration when it should be a basic function on any system with users administration...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.