REST add/update a user

Anyone have example code, or know where I can find any, for using rest to add/update/delete users, including their passwords.

Thanks,
Joel

Joel Schuweiler wrote:

Anyone have example code, or know where I can find any, for using rest to add/update/delete users, including their passwords.

Thanks,
Joel

It’s just a form, with the id: field set to “user/” instead of
“ticket/”, and use the “edit” REST method. To create a user, you’d
use the object id “user/new”. The rest of the form would be like:

id: user/new
Name: Some Name
EmailAddress: some@name.com
Organization: Some Corp
Password: blahblah
Comments: This is a comment.

and so on.

– ============================
Tom Lahti
BIT Statement LLC

(425)251-0833 x 117
http://www.bitstatement.net/
– ============================

Hrm… I thought xml was standard when doing rest, is this not the case? Is there a method to get rt to handle xml for bother get/post ?From: Tom Lahti [mailto:toml@bitstatement.net]
Sent: Friday, February 27, 2009 2:24 PM
To: Joel Schuweiler
Cc: rt-users@lists.bestpractical.com
Subject: Re: [rt-users] REST add/update a user

Joel Schuweiler wrote:

Anyone have example code, or know where I can find any, for using rest to add/update/delete users, including their passwords.

Thanks,
Joel

It’s just a form, with the id: field set to “user/” instead of
“ticket/”, and use the “edit” REST method. To create a user, you’d
use the object id “user/new”. The rest of the form would be like:

id: user/new
Name: Some Name
EmailAddress: some@name.com
Organization: Some Corp
Password: blahblah
Comments: This is a comment.

and so on.

– ============================
Tom Lahti
BIT Statement LLC

(425)251-0833 x 117
http://www.bitstatement.net/
– ============================

Joel Schuweiler wrote:

Hrm… I thought xml was standard when doing rest, is this not the case?
Is there a method to get rt to handle xml for bother get/post ?

Nope. RT uses RFC822 formatted forms, not XML. You can write a library
that transforms your XML into the forms and vice versa, if you want to code
to XML for some reason.

But if you are coding in perl, just use RT::Client::REST from CPAN. If you
are coding in ruby, wait a week or two and I’ll be open sourcing a gem. If
you are coding in something else – write your own. :wink:

– ============================
Tom Lahti
BIT Statement LLC

(425)251-0833 x 117
http://www.bitstatement.net/
– ============================

-----Original Message-----
From: rt-users-bounces@lists.bestpractical.com
[mailto:rt-users-bounces@lists.bestpractical.com] On Behalf
Of Tom Lahti
Sent: Friday, February 27, 2009 12:56 PM
To: Joel Schuweiler
Cc: rt-users@lists.bestpractical.com
Subject: Re: [rt-users] REST add/update a user

Joel Schuweiler wrote:

Hrm… I thought xml was standard when doing rest, is this
not the case?
Is there a method to get rt to handle xml for bother get/post ?

Nope. RT uses RFC822 formatted forms, not XML. You can
write a library that transforms your XML into the forms and
vice versa, if you want to code to XML for some reason.

But if you are coding in perl, just use RT::Client::REST from
CPAN. If you are coding in ruby, wait a week or two and I’ll
be open sourcing a gem. If you are coding in something else
– write your own. :wink:

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…)

Gary L. Greene, Jr.
IT Operations
Minerva Networks, Inc.
Tel: (408) 240-1239
Cell: (650) 704-6633

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…)

Well, I can tell you off the top of my head that what you POST is XML, but
the contents of that XML are not what you would think. You want one
parameter called “content” that contains the RFC822 formatted form as I
described, and that’s all thats in the XML. You can see a lot of the fields
you can set in the form by doing “/opt/rt/bin/rt edit -t user ”

If you want actual code, that’ll take longer and I don’t have time today.
And any code I show you will be in ruby.

– ============================
Tom Lahti
BIT Statement LLC

(425)251-0833 x 117
http://www.bitstatement.net/
– ============================

-----Original Message-----
From: Tom Lahti [mailto:toml@bitstatement.net]
Sent: Friday, February 27, 2009 3:32 PM
To: Gary Greene
Cc: Joel Schuweiler; rt-users@lists.bestpractical.com
Subject: Re: [rt-users] REST add/update a user

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…)

Well, I can tell you off the top of my head that what you
POST is XML, but the contents of that XML are not what you
would think. You want one parameter called “content” that
contains the RFC822 formatted form as I described, and that’s
all that’s in the XML. You can see a lot of the fields you
can set in the form by doing “/opt/rt/bin/rt edit -t user ”

If you want actual code, that’ll take longer and I don’t have
time today.
And any code I show you will be in ruby.

Ruby works for me, since I can translate that to Perl or Java fairly easily (learned ruby while surrounded by Pythonistas when I was working for Google…)

Gary L. Greene, Jr.
IT Operations
Minerva Networks, Inc.
Tel: (408) 240-1239
Cell: (650) 704-6633

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…)

Well, I can tell you off the top of my head that what you POST is XML, but
the contents of that XML are not what you would think.

Nope, it’s a regular form-encoded post. There’s no XML anywhere.

Well, I can tell you off the top of my head that what you POST is XML, but
the contents of that XML are not what you would think.

Nope, it’s a regular form-encoded post. There’s no XML anywhere.

Ah, I was right the first time. It’s been about 2 weeks since I was at the HTTP
level with my library and I thought I remembered XML, but that must have been
for something else.

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//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/
– ============================