How to disable an existing user via WS API?
The curl example below uses API Key authentication.?
Follow the same syntax after replacing placeholder "zsessionid:<API Key - include the underscore before the key> with a valid API Key of a user who has sufficient permissions (subscription or workspace admin) to disable users, and <USER_OID> with valid ObjectID of the user.
curl --header "zsessionid:<API Key - include the underscore before the key>" -H "Content-Type: application/json" -d"{\"User\":{\"Disabled\":\"true\"}}" https://rally1.rallydev.com/slm/webservice/v2.0/user/<USER_OID>
?
Notice that the payload explicitly specify the object type(User):
{\"User\":{\"Disabled\":\"true\"}}"
Note the endpoint: it points to the existing user:
https://rally1.rallydev.com/slm/webservice/v2.0/user/<USER_OID>
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 = "<VENDOR_NAME>"
headers.version = "1.0"
# Connection to Rally
config = {:base_url => "https://rally1.rallydev.com/slm"}
config[:api_key] = "<API Key - include the underscore before the key>
config[:workspace] = "<WORKSPACE_NAME>"
config[:project] = "<PROJECT_NAME>"
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 = \"<[email protected]>\")"
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}
user.update(field_updates)
puts "Is #{user} now disabled? #{user["Disabled"]}"
end