Reputation: 2293
I'm new to Perl and really struggling to understand how to do this. I'm trying to create a ticket using the Perl module RT::Client::REST, here's my code so far.
#!/usr/bin/env perl
use strict;
use warnings;
use RT::Client::REST;
use Rt::Client::REST::Ticket;
my $rt = RT::Client::REST->new(
server => ($ENV{RTSERVER} || 'http://rt.myrturl.com'),
);
$rt->login(
username => 'user',
password => 'pass',
);
my $ticket = RT::Client::REST::Ticket->new(
rt => $rt,
queue => "General - unassigned",
subject => "Perl Create Ticket Test",
);
$ticket->store("I'm a ticket");
This code isn't making the ticket and I don't know how to get any kind of good debugging output from Perl. Based on the documentation for RT::Client::REST at RT::Client::REST::Ticket, $ticket->store() should create the ticket. Does anyone have any familiarity with the module that might be able to help?
EDIT: I added print statements throughout the code as so:
#!/usr/bin/env perl
use strict;
use warnings;
use RT::Client::REST;
use Rt::Client::REST::Ticket;
my $rt = RT::Client::REST->new(
server => ($ENV{RTSERVER} || 'http://rt.myrturl.com'),
);
print "1";
$rt->login(
username => 'user',
password => 'pass',
);
print "2";
my $ticket = RT::Client::REST::Ticket->new(
rt => $rt,
queue => "General - unassigned",
subject => "Perl Create Ticket Test",
);
print "3";
$ticket->store("I'm a ticket");
The following error is thrown on the print 2 line:
Unknown code ref type given ''. Check your usage & try again at CreateRTTicket.pl line 19
Upvotes: 1
Views: 1217
Reputation: 601
If your goal is to create tickets in RT from a script, there are two other approaches you should probably try before going straight at the underlying REST code.
If you want to call the REST API, take a look at the examples on the community wiki, specifically starting with the Perl example.
Depending on what you're doing, you can also call the rt command-line client from your code. You can find docs by typing
/opt/rt4/bin/rt help
Once you get that working, you can call it from your script using system
or backticks from Perl. You can also install the rt command-line client on a separate machine using the stand-along module and can call RT from there.
Upvotes: 2
Reputation: 13391
Make a private copy of RT/client/REST.pm in your tree if you haven't already. Open it an editor and find sub _submit
. See these lines in it:
# Then we send the request and parse the response.
#DEBUG(3, $req->as_string);
my $res = $self->_ua->request($req);
#DEBUG(3, $res->as_string);
Uncomment the DEBUG
lines, and try your script again. You should see your raw HTTP request and responses appear on STDERR, which should help with debugging.
I found this by starting with the 'store' routine you mentioned, and just tracing from there to find where the raw HTTP response and request were happening.
A tool like the Advanced REST Client for Chrome could help you test and refine the raw HTTP transactions. Once you have it working at the raw HTTP level, you'll perhaps have an understanding how to proceed at the Perl API level.
Also, as the docs illustrate, you should be catching and checking your exceptions. You could be die'ing before you even get to the store
call. For that matter, as a temporary debugging measure, you could print
something in between each call, as a simple reality check that the script has advanced past each step.
Upvotes: 1