Ok, so i'm trying to comment an existing ticket with an attachment :
<?php
$request = new HttpRequest( $conf['rt']['url'] .
'/REST/1.0/ticket/' . $ticket_id . '/comment?user=' .
$conf['rt']['user'] . '&pass=' . $conf['rt']['password'], HTTP_METH_POST );
// First way : attachment is directly in the request content
$post_data = array( 'content' => "id: " . $ticket_id . "\nAction:
comment\nText: Fichier joint\nAttachment: " .
$_FILES['uploadedfile']['name'] . "\nattachment_1: " .
file_get_contents( $_FILES['uploadedfile']['tmp_name'] ) . "\n" );
//Second way : i'm adding the attachment using postfile
$post_data = array( 'content' => "id: " . $ticket_id . "\nAction:
comment\nText: Fichier joint\n" );
$request->addPostFields( $post_data );
$request->addPostFile( $_FILES['uploadedfile']['name'],
file_get_contents( $_FILES['uploadedfile']['tmp_name'] ) );
$result = $request->send();
?>
Either way, it doesn't work.
First way gives me a syntax error :
HttpMessage Object
(
[type:protected] => 2
[body:protected] => RT/3.8.10 409 Syntax Error
# Syntax error.
id: 48
Action: comment
Text: Fichier joint
Attachment: ftp_networth.jpg
attachment_1: \xFF\xD8\xFF\xE0 JFIF ` ` \xFF\xE1\xE8Exif MM * ;
#K-\xB4\xF3\xE5<\xC5d\xC90\xAA\x9D\xCA\xDF+60pGKY^!\xD1cÖ¡\xB5\xFF
J\xB9\xB2\xBB\xB4\x9B\xED\xB7v\xDB
Second way gives me this error :
PHP Fatal error: Uncaught exception 'HttpInvalidParamException' with
message 'Empty or too short HTTP message
What am i doing wrong ?
I searched in this list archive and google but I didn't find any example
on how to send an attachment with PHP and the API.
Regards,
Guillaume Hilt
Le 21/04/2012 10:13, Guillaume Hilt a écrit :
Thanks.
I didn't know there was a way to search into the archive. It's really
useful.
Guillaume Hilt
Le 19/04/2012 14:54, Kevin Falcone a écrit :
On Wed, Apr 18, 2012 at 11:57:20AM +0200, Guillaume Hilt wrote:
I'm using RT 3.8.1 and REST API in PHP.
I'm creating a ticket this way :
$request = new HttpRequest( $conf['rt']['url'] .
'/REST/1.0/ticket/new?user=' . $conf['rt']['user'] .'&pass=' .
$conf['rt']['password'], HTTP_METH_POST );
$rt_queue =
$conf['rt']['languages'][$conf['rt']['fallback_language']];
$post_data = array( 'content' => "Queue: " . $rt_queue .
"\nRequestor: " . $_SESSION['customer']['login'] . "\nCF-OS: " .
$_POST['os'] . "\nSubject: " . $_POST['subject'] . "\nOwner: " .
$_SESSION['customer']['login'] . "\nText: " . str_replace( "\n", "\n
", $_POST['message'] ) . "\n" );
$request->addPostFields( $post_data );
$request->send();
It works well.
Now i'm trying to add an attachment.
I tried to add "attachment_1: my file content" to my post data but
it doesn't work.
What's the way to attach a file to a ticket using PHP ?
If you search the mailing list archives, you'll find that you can't
create a ticket with an attachment via the REST api, only
reply/comment with an attachment. I believe there is already a ticket
open about it.
-kevin