How to Deactivate/Activate a User Through API
Purpose
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
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.
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:
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
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'