Disable user with Web Services API

Document ID : KB000057573
Last Modified Date : 14/02/2018
Show Technical Document Details


How to disable an existing user via WS API?


The curl example below uses API Key authentication.?

Follow the same syntax after replacing placeholder _abc123 with a valid API Key of a user who has sufficient permissions (subscription or workspace admin) to disable users, and 777 with valid ObjectID of the user.
curl --header "zsessionid:_abc123" -H "Content-Type: application/json" -d"{\"User\":{\"Disabled\":\"true\"}}" https://rally1.rallydev.com/slm/webservice/v2.0/user/777

Notice that the payload explicitly specify the object type(User):


Note the endpoint: it points to the existing user:


The payload above will not work if you want to create a new disabled user.

Here is a Ruby code example that disables a user:

require 'rally_api'

#Setup custom app information
headers = RallyAPI::CustomHttpHeader.new()
headers.name = "Create image attachment, add inline to the description"
headers.vendor = "Nick M RallyLab"
headers.version = "1.0"

# Connection to Rally
config = {:base_url => "https://rally1.rallydev.com/slm"}
config[:api_key] = "_abc123
config[:workspace] = "W" 
config[:project] = "P"
config[:headers] = headers #from RallyAPI::CustomHttpHeader.new() 
config[:version] = "v2.0"

@rally = RallyAPI::RallyRestJson.new(config)

#find user by username
query = RallyAPI::RallyQuery.new()
query.type = "user"
query.fetch = "Disabled"
query.query_string = "(UserName = \"nicktemp2@wsapi.com\")"

result = @rally.find(query)
user = result.first

#check if the user is currently enabled
puts "Is #{user} currently disabled? #{user["Disabled"]}"

#if the user is currently enabled, disable the user
if !user["Disabled"]
  field_updates = {"Disabled" => true}
  puts "Is #{user} now disabled? #{user["Disabled"]}"

The output in the terminal looks like this:

Is nicktemp2 currently disabled? false
Is nicktemp2 now disabled? true

A more complex java code example that disables users?who have not been logged in to Rally within past 90 days is available "as is" in?Rally Community repository. This code example is for demonstration purposes only and is not supported by Rally.