[rt-users] REST add/update a user
Tom Lahti
toml at bitstatement.net
Mon Mar 2 14:37:22 EST 2009
> Can we please get some example code for this up somewhere so those of us
> that have automated employee fulfillment workflows can integrate this
> fairly easily? At the moment, I've a JSP utility that is used to create
> new users, and I'd like pre-instantiate the RT user for them (While we do
> use the ExternalAuth LDAP integration, the user still needs to login once
> for IT to add them to the proper queue...)
Here's some code, finally had time. This is in ruby using only standard
libraries.
-----
#!/usr/bin/ruby
require 'net/http'
require 'net/https'
def rest_dump(resp,data)
puts "=" * 78
puts "HTTP response code: #{resp.code}"
puts "HTTP message: #{resp.message}"
puts "-" * 78
puts "Response:"
resp.each do |key,val|
puts "#{key} => #{val}"
end
puts "-" * 78
puts "Data:"
puts data
end
http = Net::HTTP.new('tickets.yourdomain.com', 443)
http.use_ssl = true
user = 'root'
pass = 'xxxxxxxxxxxxx'
# Log in to RT and get some data
login = "user=#{user}&pass=#{pass}"
headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
resp, data = http.post('/REST/1.0/user/toml/show',login,headers)
# Note: you can save the cookie here and not send the user/pass
# on subsequent requests. Code omitted for brevity.
rest_dump(resp,data) # display the results of user/<user>/show
# create a new user
data = login + "&content=id: user/new\nName: Some One\nEmailAddress:
someone\@somewhere.com"
resp, data = http.post('/REST/1.0/user/new/edit',data,headers)
rest_dump(resp,data)
# edit a user. For a full field list see "/opt/rt/bin/rt edit -t user 1"
data = login + "&content=id: user/toml\nDisabled: 1\nPassword: newpass\n"
resp, data = http.post('/REST/1.0/user/toml/edit',data,headers)
rest_dump(resp,data)
--
-- ============================
Tom Lahti
BIT Statement LLC
(425)251-0833 x 117
http://www.bitstatement.net/
-- ============================
More information about the rt-users
mailing list