[rt-users] Creating New User through API

Emmanuel Lacour elacour at easter-eggs.com
Wed Jun 16 01:51:08 EDT 2010


On Tue, Jun 15, 2010 at 02:20:45PM -0400, scott 2600 wrote:
> Hello -
> 
> We run a call center for our local schools.  One thing we have done recently
> is create a web based system for our interns that man the helpdesk so they
> receive a  call with a problem, obtain the user's email address and are able
> to pull up all kinds of information about their district (outages in
> district, past tickets and open tickets for the user etc).
> 
> Everything works great, except if the user has never submitted a ticket in
> RT.
> 
> What I had started with was creating  a new entry in the USERS table for
> them.  I missed groupmembers and cachedgroupmembers - but I think I want to
> abandon touching the db direct and using the API (I did the db direct for
> expediency for our needs).
> 
> So I need help working with the RT::User API.   Maybe this is  just a Perl
> 101 lesson, but where do I find how to use the calls that are available in
> there?   Is there a good spot that has some code examples on how to use that
> ?   I have the book RT Essentials and I see it exists, but haven't put
> together how to use any of the f unctions (or what they are), and a Google
> search didn't yield what I needed either.
> 
> I appreciate any and all suggestions.
> 

Short and incomplete explanation: every RT objects (User, Groups, Users,
Groups, Ticket, ...) are documented in corresponding file in
lib/RT/....pm, for example perldoc lib/RT/User_Overlay.pm.

But the easiest way to start understanding how it could be used is to
look at code used in mason templates, for example
share/html/Admin/Users/Modify.html.

You can also find examples in scrips actions/conditions provided at
http://wiki.bestpractical.com/.

In your case, creating a new user can be done with something like:

my $User = RT::User->new( $RT::SystemUser );
my ($val, $msg) = $User->LoadOrCreateByEmail( 'hi_address at email' );
unless ( $val ) {
    warn "Couldn't create or load user: $msg\n";
}


but if you wan't to create it with specific Name, RealName, ... you have
to:

first check if it doesn't already exists with $User->Load(...) or
$User->LoadByEmail(...);, then create it with $User->Create(...)





More information about the rt-users mailing list