Create RT ticket via perl, within RT but not via web interface?

I have a data collection app that needs to finish by created a ticket.
The app itself is protected by RT’s authentication (user and password), and
the app uses RT’s mason environment.

RT::Client::REST is demanding a login. I don’t have the user’s credentials,
so I figure I need to find the RT session cookie and pass that.

What’s the proper way to pull the session cookie out of $m or $r, and is
this the best way to get the new ticket created?

Thanks,
Len.

lenjaffe@jaffesystems.com 614-404-4214 www.lenjaffe.com
Proprietor: http://www.theycomewithcheese.com/ - An Homage to Fromage
Perl Advent Planet http://www.lenjaffe.com/PerlAdventPlanet/ - Advent
Calendars: Perlish and otherwise.
Greenbar http://www.greenbartraining.org/: Grubmaster: 2012-2009, Grub
Asst: 2008, Trained: 2007.

I have a data collection app that needs to finish by created a ticket.
The app itself is protected by RT’s authentication (user and password),
and the app uses RT’s mason environment.

RT::Client::REST is demanding a login. I don’t have the user’s
credentials, so I figure I need to find the RT session cookie and pass that.

What’s the proper way to pull the session cookie out of $m or $r, and is
this the best way to get the new ticket created?

Since you’re using RT’s Mason handling, you should use the Perl API
directly instead of using the REST API via RT::Client::REST. Using REST
would be an added level of indirection and complexity in that scenario.

You want to look at the CreateTicket() function provided to Mason
components by RT::Interface::Web and how it’s used elsewhere. In a
nutshell, it constructs an RT::Ticket object using $session{CurrentUser}
(an RT::CurrentUser object) as the current user and then calls ->Create.

Use perldoc to read the Perl API doc, or browse our doc site:
http://bestpractical.com/rt/docs/4.0/

Some parts of the doc are much better than others, but as a baseline
it’s a good start.

Please keep mail on the list for future folks to find.

You were right. I could not find any examples, and I’ve discovered that
CreateTicket, while it lived in RT/Interface/Web.pm, there is a second
package statement in the middle of that file, above the definition of
CreateTicket, that declares package HTML::Mason::Commands.

There are a definitely a few places in RT (under share/html/) that call
CreateTicket:

tom@whaam rt (4.0-trunk=) $ grep -rl CreateTicket share/html/
share/html/Elements/CreateTicket
share/html/Elements/Tabs
share/html/Elements/ShowLinks
share/html/Elements/SelectQueue
share/html/Tools/Offline.html
share/html/index.html
share/html/SelfService/Display.html
share/html/SelfService/CreateTicketInQueue.html
share/html/Ticket/Display.html
share/html/m/ticket/select_create_queue
share/html/m/ticket/show

So I had to call HTML::Mason::Commands::CreateTicket(0 which was
unexpected and took me a while to suss out.

All Mason files – and you said you were inside RT’s mason framework –
use the HTML::Mason::Commands package. You don’t need to fully qualify
the call to CreateTicket(), you can just call it if you’re in a Mason file.

Thomas