ELI5: How do I disable a user in Confluence using a rest API
Asked by Mark Robbins:

Hey all

I'm trying to automate as much of my life as possible so I want to disable users via a script. I just can't seem to figure out why I can't get any joy on disabling users in my confluence space. The command I'm running is as follows

curl -i -H "Authorization: Bearer \<TOKEN\>" -X PUT --data '{"active":"false"}' https://\<URL\>/rest/api/user?username=\<username\> --header 'Content-Type: application/json' --header 'Accept: application/json'

And I've tried a bunch of different variations but I cant get any joy

Explain like I'm 5: How do I make it work?


Answers:
author: Thiago Masutti
body: Hi [@Mark Robbins](/t5/user/viewprofilepage/user-id/4712204) .  
Welcome to the Atlassian Community :)

Currently there's no REST API to deactivate a user on Confluence.  
See [CONFSERVER-56205](https://jira.atlassian.com/browse/CONFSERVER-56205) and [CONFSERVER-54928](https://jira.atlassian.com/browse/CONFSERVER-54928) for future reference on this feature.

As a workaround you may want to use the [legacy RPC API methods](https://developer.atlassian.com/server/confluence/remote-confluence-methods/#user-management) for it.

You may need to do the following:

1. [Turn off secure administrator sessions](https://confluence.atlassian.com/doc/configuring-secure-administrator-sessions-218269595.html#ConfiguringSecureAdministratorSessions-Turnoffsecureadministratorsessions).
2. [Enable the remote API](https://confluence.atlassian.com/doc/enabling-the-remote-api-150460.html) .
3. Run the API call below, making the necessary changes on the parameters.

```
ADMIN_USERNAME=admin
ADMIN_PASSWORD=admin
CONFLUENCE_BASEURL=http://localhost:27161/c7161
TARGET_USERNAME=user001



JSON_RPC_METHOD=deactivateUser
curl -s \
  --user ${ADMIN_USERNAME}:${ADMIN_PASSWORD} \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -X POST \
  -d '{ "jsonrpc" : "2.0", "method" : "'${JSON_RPC_METHOD}'", "params" : ["'${TARGET_USERNAME}'"], "id": 7 }' \
  ${CONFLUENCE_BASEURL}'/rpc/json-rpc/confluenceservice-v2?os_authType=basic'
```

On the above I'm using basic authentication with username and password.  
You can change it to the access token authentication as you mentioned.

Let me know if that works.

Kind regards,  
Thiago Masutti

comments: author: Mark Robbins
body: Hey [@Thiago Masutti](/t5/user/viewprofilepage/user-id/1209618)

Thanks for coming back to me. That's probably not gonna work out in my environment unfortunately.

I assume that in the SQL db there is something flagging that the user is active yes? something that could be modified or deleted to switch the user to inactive?

Kind Regards

Mark


author: Daniel Ebers
body: Hi [@Mark Robbins](/t5/user/viewprofilepage/user-id/4712204)

if I get it right the question is how to deactive an user via database.  
While it is reported to be possible - it is agains best practise and on top it seems a restart of Confluence is needed.

Not that I would promote that route, there has been a similar discussion here in Community:  
<https://community.atlassian.com/t5/Confluence-questions/Disable-users-from-Confluence-database/qaq-p/391075>

You could check if this is what you are after.

Regards,  
Daniel


author: Makareswar Rout
body: It worked for me - I just loop inside a bash script and it cleaned 3k users in 2--25 minutes.


Tags: confluence-server

server