Could there be a REST/ticket creation bug?

I first posted the message below to rt-users thinking I was doing something wrong in my application’s PHP code that is trying to submit a REST request to RT… but having added debugging comments to RT code I think possibly there could be a bug? Please read and then look below for the rest of this message…From: "vtplymblfan-rt@yahoo.com" vtplymblfan-rt@yahoo.com
To: rt-users@lists.bestpractical.com
Sent: Tuesday, May 19, 2009 12:53:21 PM
Subject: [rt-users] any ideas why this post with php CURL not setting custom field?

Hi there,

I
have modified a web application to post to RT’s web interface a create
ticket request. The post works perfectly… the ticket get created in
the right queue with the given subject and text… except that the
custom field value I pass (UPC) in does not get set. Here is the CURL
code:

$content = 'id: new

CF-UPC: 786936180992
Text: This is the ticket text
Subject: This is the subject
Queue: External App Requests’;

$request = RT_LOCATION;
$request .= 'ticket/new/';

$postargs = array(
   'user' => RT_USER,
   'pass' => RT_PASS,
   'content' => $content
);

// get the curl session object
$session = curl_init($request);

// set the POST options
curl_setopt ($session, CURLOPT_POST, true);
curl_setopt ($session, CURLOPT_POSTFIELDS, $postargs);
curl_setopt($session, CURLOPT_HEADER, true);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $session, CURLOPT_HTTPHEADER, array( 'Expect:' ) );

// do the POST and then close the session
$response = curl_exec($session);
curl_close($session);

In debugging this I have also created a simple form which posts to the same place:

User:
Pass:
Content: id: new CF-UPC: 786936180992 Text: This is the ticket text from the form. Subject: This is the subject Queue: External App Requests

When this form is used, again the ticket is created but in this case the custom field UPC does get set. But
the “Content:” being sent is the same in both. In particular in both cases I am providing UPC’s value with
"CF-UPC: 78…" Can anyone here explain what the difference could possibly be between these two
posting methods that could result in this scenario? By the way, in both cases I am passing in the same
user name and password. I am really stumped and I suspect some small stupid thing I have missed.

Thanks for your help,
Kim

Ok so I decided to add comments to REST/1.0/Forms/ticket/default to see what RT was receiving in either case:

else {
# We’ll create a new ticket, and fall through to set fields that
# can’t be set in the call to Create().
my (%v, $text);

    foreach my $k (keys %data) {

push(@comments, “------------key: $k----------”);
# flexibly parse any dates
if ($dates{lc $k}) {
my $time = new RT::Date $session{CurrentUser};
$time->Set(Format => ‘unknown’, Value => $data{$k});
$data{$k} = $time->ISO;
}

        if (exists $create{lc $k}) {

push(@comments, “key $k in create”);
$v{$create{lc $k}} = delete $data{$k};
}
# Set custom field
elsif ($k =~ /^$cf_spec/) {
push(@comments, “GOT HERE with $k”);
my $cf = RT::CustomField->new( $RT::SystemUser );
push(@comments, “cf: $cf”);
my $cfk = $1 || $2;
push(@comments, “cfk: $cfk”);
unless($cf->LoadByName( Name => $cfk )) {
push @comments, “# Invalid custom field name ($cfk)”;
delete $data{$k};
next;
}
push(@comments, “value: $data{$k}”);
my($foo) = $cf->Id();
push(@comments, “foo: $foo”);

            $v{"CustomField-".$cf->Id()} = delete $data{$k};

push(@comments, “v: $v{‘CustomField-’.$foo}”);
}

And I have dicovered that either way I try to create a ticket, either with the PPH CURL code or with the form, the comments that get spit out are the same:

------------key: Subject----------
key Subject in create
------------key: id----------
------------key: CF-UPC----------
GOT HERE with CF-UPC
cf: RT::CustomField=HASH(0x5555592bf510)
cfk: UPC
value: 786936180992
foo: 1
v: 786936180992
------------key: Queue----------
key Queue in create
------------key: Text----------

So it appears that in both cases Forms/ticket/default is getting exactly the same thing and doing with it exactly the same thing… specifically
taking in CF-UPC: 7893… and with that creating the custom field UPC with value 7893…

So then why in one case does the resulting ticket I find when I go to RT have this custom field set and in the other case not? Please are there any
ticket creation experts who could shed light on what is going wrong after the request is processed in Forms/ticket/default?

Thanks so much for your help,
Kim Jones

What version of RT are you using?
Does using the RT CLI fail in the same way?
Can you sniff and capture the HTTP conversation between your client code
and RT?On Fri, May 22, 2009 at 11:28:05AM -0700, Kim Jones wrote:

I first posted the message below to rt-users thinking I was doing something wrong in my application’s PHP code that is trying to submit a REST request to RT… but having added debugging comments to RT code I think possibly there could be a bug? Please read and then look below for the rest of this message…


From: "vtplymblfan-rt@yahoo.com" vtplymblfan-rt@yahoo.com
To: rt-users@lists.bestpractical.com
Sent: Tuesday, May 19, 2009 12:53:21 PM
Subject: [rt-users] any ideas why this post with php CURL not setting custom field?

Hi there,

I
have modified a web application to post to RT’s web interface a create
ticket request. The post works perfectly… the ticket get created in
the right queue with the given subject and text… except that the
custom field value I pass (UPC) in does not get set. Here is the CURL
code:


$content = 'id: new

CF-UPC: 786936180992
Text: This is the ticket text
Subject: This is the subject
Queue: External App Requests’;

$request = RT_LOCATION;
$request .= 'ticket/new/';

$postargs = array(
   'user' => RT_USER,
   'pass' => RT_PASS,
   'content' => $content
);

// get the curl session object
$session = curl_init($request);

// set the POST options
curl_setopt ($session, CURLOPT_POST, true);
curl_setopt ($session, CURLOPT_POSTFIELDS, $postargs);
curl_setopt($session, CURLOPT_HEADER, true);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $session, CURLOPT_HTTPHEADER, array( 'Expect:' ) );

// do the POST and then close the session
$response = curl_exec($session);
curl_close($session);

In debugging this I have also created a simple form which posts to the same place:

User:
Pass:
Content: id: new CF-UPC: 786936180992 Text: This is the ticket text from the form. Subject: This is the subject Queue: External App Requests

When this form is used, again the ticket is created but in this case the custom field UPC does get set. But
the “Content:” being sent is the same in both. In particular in both cases I am providing UPC’s value with
"CF-UPC: 78…" Can anyone here explain what the difference could possibly be between these two
posting methods that could result in this scenario? By the way, in both cases I am passing in the same
user name and password. I am really stumped and I suspect some small stupid thing I have missed.

Thanks for your help,
Kim


Ok so I decided to add comments to REST/1.0/Forms/ticket/default to see what RT was receiving in either case:

else {
# We’ll create a new ticket, and fall through to set fields that
# can’t be set in the call to Create().
my (%v, $text);

    foreach my $k (keys %data) {

push(@comments, “------------key: $k----------”);
# flexibly parse any dates
if ($dates{lc $k}) {
my $time = new RT::Date $session{CurrentUser};
$time->Set(Format => ‘unknown’, Value => $data{$k});
$data{$k} = $time->ISO;
}

        if (exists $create{lc $k}) {

push(@comments, “key $k in create”);
$v{$create{lc $k}} = delete $data{$k};
}
# Set custom field
elsif ($k =~ /^$cf_spec/) {
push(@comments, “GOT HERE with $k”);
my $cf = RT::CustomField->new( $RT::SystemUser );
push(@comments, “cf: $cf”);
my $cfk = $1 || $2;
push(@comments, “cfk: $cfk”);
unless($cf->LoadByName( Name => $cfk )) {
push @comments, “# Invalid custom field name ($cfk)”;
delete $data{$k};
next;
}
push(@comments, “value: $data{$k}”);
my($foo) = $cf->Id();
push(@comments, “foo: $foo”);

            $v{"CustomField-".$cf->Id()} = delete $data{$k};

push(@comments, “v: $v{‘CustomField-’.$foo}”);
}

And I have dicovered that either way I try to create a ticket, either with the PPH CURL code or with the form, the comments that get spit out are the same:

------------key: Subject----------
key Subject in create
------------key: id----------
------------key: CF-UPC----------
GOT HERE with CF-UPC
cf: RT::CustomField=HASH(0x5555592bf510)
cfk: UPC
value: 786936180992
foo: 1
v: 786936180992
------------key: Queue----------
key Queue in create
------------key: Text----------

So it appears that in both cases Forms/ticket/default is getting exactly the same thing and doing with it exactly the same thing… specifically
taking in CF-UPC: 7893… and with that creating the custom field UPC with value 7893…

So then why in one case does the resulting ticket I find when I go to RT have this custom field set and in the other case not? Please are there any
ticket creation experts who could shed light on what is going wrong after the request is processed in Forms/ticket/default?

Thanks so much for your help,
Kim Jones


List info: http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-devel