How to delete users using jira rest api

Yuval Maron May 31, 2021

Hey,

I saw in the documentation this method https://docs.atlassian.com/software/jira/docs/api/REST/7.12.0/#api/2/user-removeUser but It doesn't work for me. 

I've tried to send the relevant accountId and as GET method I do get the relevant user but it doesn't work when I try to delete it.

 

Thanks in advance!

1 answer

0 votes
Charlie Misonne
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 31, 2021

Hi Yuval,

Do you get a response from the server when executing the delete method? If so, what's the message and what's the response code?

If you use curl please share your command so we can troubleshoot it or share a screenshot from your Postman or any tool you might be using.

Yuval Maron May 31, 2021

Hey @Charlie Misonne 

I'm using postman+JS but I first started with postman in order to see that actually works before iterating through all the users.

This is the GET which does respond correctly: image.png

But when I try to delete it: 

image.png
it doesn't show anything and it didn't delete the user.

In addition I used the following script to delete projects and it did work ( even if the post man delete method didn't show any response):


axios
.get(
session_url,
{ auth: {
username: '****',
password: '*****'},

}
)
.then(function (response) {
let res= response.data;
let idArr=new Array();
for(var key in res){
idArr.push(res[key]['id']);

}
console.log(idArr);
for(var id in idArr){

axios.delete(
session_url+'/'+idArr[id],
{ auth: {
username: '*****',
password: '*****'},

}
)


;

}
});

Charlie Misonne
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 31, 2021

Ok, I can see a first reason already.

You were looking at the documentation for Jira SERVER and not for Jira Cloud which you seem to be using.

Cloud and Server do not share exactly the same REST endpoints.

Here is the documentation for Cloud: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-users/#api-rest-api-3-user-delete

The endpoint is /rest/api/3/user. 3 instead of 2. Can you try changing that and test again?

You also need to be a site administrator but I assume you are.

Yuval Maron May 31, 2021

Hey thank you for the quick response, It didn't work either. 

Charlie Misonne
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 31, 2021

Well that's odd. In your screenshot I see you get a 204 response and that should mean the user was removed successfully.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events