Help build a JSON request

I’m trying to build a JSON request so that I can shoot info from RT to an external site.

I’m using a custom component to build and execute the request, and then also handle the response.

My challenge is that I am not able to get a custom field value, which I would like to add to the JSON request.

Within the component, I use this to capture the ticket object

my $TicketObj ||= LoadTicket($OriginalTicket);

All I would like to do is grab the value from a custom field on that ticket. When I try to use

my %category_open = CustomField->Load(4);

I get "Can’t locate object method “Load” via package “CustomField”… which doesn’t make sense to me, since that should already be included. I’m guessing on the syntax for using CustomField->Load as I could find no examples in the documentation, but I assumed I would get a different error message to help me figure it out.

RT version 4.4.2

Thanks!

Without seeing the rest of the script/scrip its a bit tricky to help you debug this, but the error looks like it might be because you’re missing the RT:: part at the front of the calls so it doesn’t know what object you’re trying to call the Load() method on. You might want something like (for example):

my $cf = RT::CustomField->new($RT::SystemUser);
$cf->Load(4);

If this is a script rather than a scrip, remember that you’ll need to include use RT::Tickets and/or use RT::CustomField and probably call RT::LoadConfig(); and RT::Init();.

I found what I needed with some additional forum scouring:

$cf_info = $TicketObj->FirstCustomFieldValue(Field => ‘4’);

I didn’t realize what was available from the RT::Record object.

Thanks though!

Oops, more like:

$cf_info = $TicketObj->FirstCustomFieldValue(‘4’);

Would anyone be so kind as to post the contents of $TicketObj? Not any specific values, I just want to see the names of the members of the object.

Thanks in advance!

Do you mean the methods that you can call on the object? Take a look at the documentation for RT::Ticket for those.

I’m not particularly interested in methods, just data items such as Id, Priority, Status, etc. Also any custom fields.

In particular, I want to see what the field names look like inside RT, since they aren’t always identical to what you see in the UI.

So what I really need right now is an actual working example of how to request everything from an existing ticket using the REST 2.0 interface via PHP & cURL. (Or even at the command line.) It seems like every time I try something that I haven’t done before, the documentation falls short of telling me what I need to know. Command line is OK for a quick test but I’ll have to implement it in a PHP script that can be run from a cron job for daily record-keeping.

The simplest example of getting all the data on a ticket can be as follows:

curl -X GET -u ‘root:password’ ‘MyURL/REST/2.0/ticket/1’

You can expect a return like the following:

{
“Type” : “ticket”,
“LastUpdatedBy” : {
“id” : “root”,
“_url” : “MyURL/REST/2.0/user/root”,
“type” : “user”
},
“Owner” : {
“id” : “root”,
“type” : “user”,
“_url” : “MyURL/REST/2.0/user/root”
},
“Starts” : “1970-01-01T00:00:00Z”,
“_hyperlinks” : [
{
“ref” : “self”,
“id” : “1”,
“type” : “ticket”,
“_url” : “MyURL/REST/2.0/ticket/1”
},
{
“_url” : “MyURL/REST/2.0/ticket/1/history”,
“ref” : “history”
},
{
“_url” : “MyURL/REST/2.0/ticket/1/correspond”,
“ref” : “correspond”
},
{
“ref” : “comment”,
“_url” : “MyURL/REST/2.0/ticket/1/comment”
},
{
“update” : “Comment”,
“label” : “Stall”,
“ref” : “lifecycle”,
“_url” : “MyURL/REST/2.0/ticket/1/comment”,
“to” : “stalled”,
“from” : “open”
},
{
“label” : “Resolve”,
“ref” : “lifecycle”,
“update” : “Comment”,
“from” : “open”,
“_url” : “MyURL/REST/2.0/ticket/1/comment”,
“to” : “resolved”
},
{
“update” : “Respond”,
“ref” : “lifecycle”,
“label” : “Reject”,
“to” : “rejected”,
“_url” : “MyURL/REST/2.0/ticket/1/correspond”,
“from” : “open”
}
],
“Priority” : “0”,
“TimeLeft” : “0”,
“TimeEstimated” : “0”,
“id” : 1,
“LastUpdated” : “2018-09-07T17:20:44Z”,
“Due” : “1970-01-01T00:00:00Z”,
“Queue” : {
“id” : “1”,
“type” : “queue”,
“_url” : “MyURLREST/2.0/queue/1”
},
“AdminCc” : [],
“Resolved” : “1970-01-01T00:00:00Z”,
“EffectiveId” : {
“id” : “1”,
“_url” : “MyURL/REST/2.0/ticket/1”,
“type” : “ticket”
},
“FinalPriority” : “0”,
“Creator” : {
“_url” : “MyURL/REST/2.0/user/root”,
“type” : “user”,
“id” : “root”
},
“Subject” : “My First Ticket!”,
“InitialPriority” : “0”,
“Created” : “2018-09-07T17:20:43Z”,
“Requestor” : [
{
“id” : “root”,
“_url” : “MyURL/REST/2.0/user/root”,
“type” : “user”
}
],
“TimeWorked” : “0”,
“CustomFields” : {},
“Status” : “open”,
“Cc” : [],
“Started” : “2018-09-07T17:20:43Z”
}