It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Bulk delete users

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

8 answers

1 accepted

0 votes
Answer accepted
Anna Cardino Atlassian Team May 21, 2014

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.

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];
}

}

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]);
Like # people like this

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();

 

Like # people like this

Here's a working version:

 


var baseURL = 'https://raprec.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!'));

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.

 

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();

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

And deleted :)

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

 

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. 

Is there a plugin for Cloud? The above is just for server

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 !

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

273 views 1 2
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you