How can I deactivate a user using curl

Hello!  I'm using the following command to try to deactivate a user, but it's not working:

curl -k -v -u admin:password -H "X-Requested-With: XMLHttpRequest" -H "Content-Type: application/json"  -X POST https://jira-server.atlassian.net/admin/rest/um/1/user/deativate?username=user2delete

* About to connect() to jira-server.atlassian.net port 443 (#0)
*   Trying 104.192.140.242... connected
* Connected to jira-server.atlassian.net (104.192.140.242) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* warning: ignoring value of ssl.verifyhost
* skipping SSL peer certificate verification
* SSL connection using TLS_RSA_WITH_AES_128_CBC_SHA
* Server certificate:
*       subject: CN=*.atlassian.net,O="Atlassian Network Services, Inc.",L=San Francisco,ST=California,C=US
*       start date: Sep 09 00:00:00 2014 GMT
*       expire date: Nov 15 12:00:00 2017 GMT
*       common name: *.atlassian.net
*       issuer: CN=DigiCert SHA2 High Assurance Server CA,OU=www.digicert.com,O=DigiCert Inc,C=US
* Server auth using Basic with user 'admin'
> POST /admin/rest/um/1/user/deativate?username=user2delete HTTP/1.1
> Authorization: Basic YzlnbWF0hHdoLmWxjb21lMTIz
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.16.2.3 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: jira-server.atlassian.net
> Accept: */*
> X-Requested-With: XMLHttpRequest
> Content-Type: application/json
>
< HTTP/1.1 404 Not Found
< Server: nginx
< Date: Thu, 07 Apr 2016 18:41:50 GMT
< Content-Length: 0
< Connection: keep-alive
< Set-Cookie: studio.crowd.tokenkey=hSHRvShyG6fi6uFOya5tkQ00; Domain=jira-server.atlassian.net; Path=/; Secure; HttpOnly
< X-Application-Context: application:prod:8080
<
* Connection #0 to host jira-server.atlassian.net left intact
* Closing connection #0

4 answers

1 accepted

WAIT!!!  That was almost it!!  This actually works.  With Cloud, anyway . . .

 

curl  -u $USERNAME:$PASSWORD --header "X-Atlassian-Token: no-check" -H "X-Requested-With: XMLHttpRequest" -H "Content-Type: application/json"  -X POST https://${INSTANCE}/admin/rest/um/1/user/deactivate?username=user2deactivate

Doesn't work with 5.8.18. What Confluence version are you using?

This is for Jira, not confluence

 

Seems like it is not working anymore. I guess since atlassian forced users to chnage to atlassian account.

Anyway, I am getting "User failed to authenticate". Neither old username nor full email address works.

If anybody knows a workaround, would be awesome.

 

It's still working for me.  Can you post the output using "curl -v -s"?  Don't forget to remove the password and the "Authorization" line from the debug output

I guess Atlassian finally got around to updating my cloud instance.  The way to do this now is by using cookies to authenticate.  So, first:

curl -s -c cookie_jar.txt -H "Content-Type: application/json" --data '{"username":"admin_user@domain.com", "password":"PASSWORD"}' -X POST https://cloud_server.atlassian.net/rest/auth/1/session

Then

curl -s --cookie cookie_jar.txt  -H "Content-Type: application/json"  -X POST https://cloud_server.atlassian.net/admin/rest/um/1/user/deactivate?username=user_to_deactivate

Worked for me - Thanks! (Cloud)

Deactivating a user at his time is only possible Via the UI

The ability to Deactivate users via API is being tracked in this feature request:

 

Thanks!  But it seems like it should be possible to mimic the UI with curl, even if it's not as simple as hitting a REST endpoint, no?

I'm an idiot.  The curl command above works.  I was using the wrong password

Ignacio Pulgar Community Champion Apr 17, 2016

Could you possibly accept your answer?

If you want to delete for any reason you can follow pretty much the same info above and just change the url and the method, see below;

curl -s --cookie cookie_jar.txt  -H "Content-Type: application/json"  -X DELETE https://cloud_server.atlassian.net/admin/rest/um/1/user?username=user_to_delete

Suggest an answer

Log in or Join to answer
Community showcase
Teodora [Botron]
Published Thursday in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

265 views 0 12
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot