Hi there, I have this same problem, i need to add attachments to existing tickets via REST from php.<br><br>I wrote this small piece of code:<br><br>=-=-=-=-=-= code =-=-=-=-=-=-=-=<br>$url = "<a href="http://ticket/rt4/REST/1.0/ticket/514/comment?user=$username&pass=$password">http://ticket/rt4/REST/1.0/ticket/514/comment?user=$username&pass=$password</a>";<br>

<br>$attachment_file        = getcwd().'/somejpeg.jpg';<br>$attachment_content     = file_get_contents($attachment_file);<br><br>$file_name = 'attachment_1; filename="somejpeg.jpg"' . "\n" . 'Content-Type: image/jpeg';<br>

<br>$post_data=array($file_name=>$attachment_content, "content"=>"Ticket: 514\nAction: comment\nText: aaahhhhhhh\nAttachment: somejpeg.jpg\n");<br><br>$curl_handle=curl_init();<br>curl_setopt ($curl_handle, CURLOPT_URL,$url);<br>

curl_setopt ($curl_handle, CURLOPT_ENCODING, "deflate");<br>curl_setopt ($curl_handle, CURLOPT_COOKIEJAR, getcwd().'/cookies.txt');<br>curl_setopt ($curl_handle, CURLOPT_POST, 2);<br>curl_setopt ($curl_handle, CURLOPT_POSTFIELDS, $post_data);<br>

curl_setopt ($curl_handle, CURLOPT_HEADER, 1);<br>curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, true);<br>curl_setopt ($curl_handle, CURLOPT_HTTPHEADER, array( 'Expect:' ) );<br>$response = curl_exec($curl_handle);<br>

echo $response;<br>curl_close($curl_handle);<br>=-=-=-=-=-= end code -=-=-=-=-=-=-<br><br>In order to have a reference, I submitted the file via rt from the command line with complete success.<br>I wanted to look at what 'rt' sends so i used tcpflow to reconstruct the content, see below<br>

<br>=-=-=-=-=-= request sent by 'rt' from cli =-=-=-=-=-==<br>POST /rt4/REST/1.0/ticket/514/comment HTTP/1.1<br>TE: deflate,gzip;q=0.3<br>Connection: TE, close<br>Host: ticket<br>User-Agent: RT/3.0b<br>Content-Length: 41964<br>

Content-Type: multipart/form-data; boundary=xYzZY<br>Cookie: RT_SID_ticket.80=c593fea8c27488b8b8764196a4b257d3<br><br>--xYzZY<br>Content-Disposition: form-data; name="attachment_1"; filename="somejpeg.jpg"<br>

Content-Type: image/jpeg<br><br>(binary content)<br>--xYzZY<br>Content-Disposition: form-data; name="content"<br><br>Ticket: 514<br>Action: comment<br>Cc:<br>Bcc:<br>Attachment: somejpeg.jpg<br>TimeWorked:<br>Text: going crazy<br>

<br>--xYzZY--<br>=-=-=-=-=-=-=-= end of content sent by 'rt' =-=-=-==-=-=<br><br><br>=-=-=-=-=-=-=-= content sent via php/curl -=-=-=-=-=-=-<br>POST /rt4/REST/1.0/ticket/514/comment?user=someuser&pass=somepassword HTTP/1.1<br>

Host: ticket<br>Accept: */*<br>Accept-Encoding: deflate<br>Content-Length: 42046<br>Content-Type: multipart/form-data; boundary=----------------------------5e8f1e2cb2d5<br><br>------------------------------5e8f1e2cb2d5<br>

Content-Disposition: form-data; name="attachment_1; filename="somejpeg.jpg"<br>Content-Type: image/jpeg"<br><br>(binary content)<br>------------------------------5e8f1e2cb2d5<br>Content-Disposition: form-data; name="content"<br>

<br>Ticket: 514<br>Action: comment<br>Text: aaahhhhhhh<br>Attachment: somejpeg.jpg<br><br>------------------------------5e8f1e2cb2d5--<br>=-=-=-=-=-=-= end of content sent via php/curl =-=-=-=-=-=<br><br><br>I think that php is unable to construct messages of type multipart/form-data correctly.<br>

By comparing the line just after the boundary (for the binary part) you'll note that they are not equal.<br>I couldn't find a way to replicate what rt generates with php.<br>I tried using a very 'unnatural' key for the file name in $post_data but it doesn't work. All i get is the<br>

infamous:<br><br>RT/4.0.2 400 Bad Request<br><br># No attachment for somejpeg.jpg.<br><br><br>Any comments?<br><br>Thanks,<br>Hugo<br><br><br><div class="gmail_quote">On Mon, Apr 23, 2012 at 10:51 AM, Guillaume Hilt <span dir="ltr"><<a href="mailto:ghilt@shadowprojects.org" target="_blank">ghilt@shadowprojects.org</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I hope so because I didn't find anything.<br>
<br>
I'm still digging and now I'm sending this kind of request to RT :<br>
<br>
HttpRequest Object<br>
(<br>
    [options:HttpRequest:private] =><br>
    [postFields:HttpRequest:<u></u>private] =>  Array<br>
        (<br>
            [content] =>  id: 56<div class="im"><br>
Action: comment<br>
Text: Fichier joint<br>
Attachment: ftp_networth.jpg<br>
<br></div>
--uploadfichiersupport--<br>
            [attachment_1] =>  filename: ftp_networth.jpg<br>
Content-Type: image/jpeg<br>
<br>
’Ų’ą .... (file content)<br>
<br>
Request Content-Type is set to "multipart/form-data; boundary=uploadfichiersupport"<u></u>.<br>
<br>
I'm trying to find my way using the VB.net example.<br>
<br>
  Guillaume Hilt<br>
<br>
<br>
Le 23/04/2012 16:29, Kevin Falcone a écrit :<div class="HOEnZb"><div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Mon, Apr 23, 2012 at 12:09:20PM +0200, Guillaume Hilt wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Ok, so i'm trying to comment an existing ticket with an attachment :<br>
<br>
<?php<br>
<br>
$request        = new HttpRequest( $conf['rt']['url'] .<br>
'/REST/1.0/ticket/' . $ticket_id . '/comment?user=' .<br>
$conf['rt']['user'] . '&pass=' . $conf['rt']['password'],<br>
HTTP_METH_POST );<br>
<br>
// First way : attachment is directly in the request content<br>
$post_data      = array( 'content' =>  "id: " . $ticket_id .<br>
"\nAction: comment\nText: Fichier joint\nAttachment: " .<br>
$_FILES['uploadedfile']['name'<u></u>] . "\nattachment_1: " .<br>
file_get_contents( $_FILES['uploadedfile']['tmp_<u></u>name'] ) . "\n" );<br>
<br>
//Second way : i'm adding the attachment using postfile<br>
$post_data      = array( 'content' =>  "id: " . $ticket_id .<br>
"\nAction: comment\nText: Fichier joint\n" );<br>
$request->addPostFields( $post_data );<br>
<br>
$request->addPostFile( $_FILES['uploadedfile']['name'<u></u>],<br>
file_get_contents( $_FILES['uploadedfile']['tmp_<u></u>name'] ) );<br>
$result         = $request->send();<br>
<br>
?><br>
<br>
Either way, it doesn't work.<br>
<br>
First way gives me a syntax error :<br>
<br>
HttpMessage Object<br>
(<br>
     [type:protected] =>   2<br>
     [body:protected] =>   RT/3.8.10 409 Syntax Error<br>
<br>
# Syntax error.<br>
<br>
id: 48<br>
Action: comment<br>
Text: Fichier joint<br>
Attachment: ftp_networth.jpg<br>
attachment_1: \xFF\xD8\xFF\xE0  JFIF     ` `  \xFF\xE1 \xE8Exif  MM *       ;  <br>
#K -\xB4\xF3\xE5<\xC5d\xC90\xAA\<u></u>x9D\xCA\xDF+60pGKY^!\xD1cÖ”\<u></u>xB5\xFF J\xB9\xB2\xBB\xB4\x9B\xED \xB7v\xDB<br>
<br>
<br>
Second way gives me this error :<br>
PHP Fatal error:  Uncaught exception 'HttpInvalidParamException'<br>
with message 'Empty or too short HTTP message<br>
<br>
What am i doing wrong ?<br>
<br>
I searched in this list archive and google but I didn't find any<br>
example on how to send an attachment with PHP and the API.<br>
</blockquote>
There are tests for this, so I know it works, I suggest using the<br>
bin/rt command line client in debug mode to see what it sends over the<br>
wire.  Otherwise, numerous people have used PHP/Python/Ruby/Java to<br>
talk to the REST api so perhaps someone will volunteer some sample<br>
code.<br>
<br>
-kevin<br>
</blockquote>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Hugo Escobar<br><br><br><img title="AFS_logo.png" alt="AFS_logo.png" src="cid:ii_12ddc99660bf2d8d" height="35" width="171"><br><br>Follow us on Facebook and Linked-In<br clear="all">

<br><a href="http://www.facebook.com/pages/Miami-FL/ASSOCIATION-FINANCIAL/64952991864" target="_blank"><img title="facebook-24x24.png" alt="facebook-24x24.png" src="cid:ii_12ddc9e6256d137a"></a> <a href="http://www.linkedin.com/companies/1006276" target="_blank"><img title="linkedin-24x24.png" alt="linkedin-24x24.png" src="cid:ii_12ddc9cb29a3a5d5"></a><br>

<br>