How to Deactivate/Activate a User Through API
Platform Notice: Data Center Only - This article only applies to Atlassian apps on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
This article describes how to make an API call activate/deactivate specific user within Crowd.
Solution
Here we have a documentation related to the Crowd REST API and JSON Requests and Responses. Take a look at it to get an overview of how Crowd works with its REST API.
Here's the call we need to run based on this URL structure: http://host:port/context/rest/api-name/api-version/resource-name
API Call
curl -i -u <application_username>:<application_password> -X PUT --data '{"name":"<username_of_the_user>", "active":"<true/false>"}' <crowd_base_url>/crowd/rest/usermanagement/1/user?username=<username_of_the_user> --header 'Content-Type: application/json' --header 'Accept: application/json'
Please note that the PUT operation on the usermanagement/1/user REST endpoint will modify other user properties such as: user email, last name, first name and display name.
In order to prevent that you should also provide values of those fields before calling this endpoint.
API Call
curl -i -u <application_username>:<application_password> -X PUT --data '{ "name": "<username_of_the_user>", "active": "<true/false>", "first-name": "<first_name_of_the_user>", "last-name": "<last_name_of_the_user>", "display-name": "<display_name_of_the_user>", "email": "<email_of_the_user>"}' <crowd_base_url>/crowd/rest/usermanagement/1/user?username=<username_of_the_user> --header 'Content-Type: application/json' --header 'Accept: application/json'
In order to get those values please run GET command as follows:
API Call
curl -i -u <application_username>:<application_password> -X GET <crowd_base_url>/crowd/rest/usermanagement/1/user?username=<username_of_the_user> --header 'Content-Type: application/json' --header 'Accept: application/json'
Here's an example considering:
The username and password are not your Crowd credentials but rather your Crowd application credentials. Only applications can connect to Crowd REST services and not individual users.
Application username: crowd
Application password: test
username_of_the_user: testuser
Status: Deactivate
crowd_base_url: https://yourcompany.com
Example
curl -i -u crowd:test -X PUT --data '{"name":"testuser", "active":"false"}' https://yourcompany.com/crowd/rest/usermanagement/1/user?username=testuser --header 'Content-Type: application/json' --header 'Accept: application/json'
Was this helpful?