Thanks Thomas Not using curl ----- $attachment_1 = file_get_contents(FCPATH . '/test.pdf');
$content = "id: 15818\n"; $content = $content . "Action: correspond\n"; $content = $content . "Text: Im adding some text\n And adding some more text\n And some more\n"; $content = $content . "TimeWorked: 30\n"; $content = $content . "Attachment: test.pdf\n"; $url = 'http://rt4.challengeltd.net/REST/1.0/'; $url .= 'ticket/15818/comment'; $post_data = array( 'user' => 'user', 'pass' => 'password', 'content' => $content, 'attachment_1' => $attachment_1 ); $data = http_build_query($post_data); $params = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $data )); $ctx = stream_context_create($params); $response = file_get_contents($url, false, $ctx); print_r($response); ------ Using curl --- $attachment_1 = file_get_contents(FCPATH . '/test.pdf'); $content = "id: 15818\n"; $content = $content . "Action: correspond\n"; $content = $content . "Text: Im adding some text\n And adding some more text\n And some more\n"; $content = $content . "TimeWorked: 30\n"; $content = $content . "Attachment: test.pdf\n"; $request = 'http://rt4.challengeltd.net/REST/1.0/'; $request .= 'ticket/15818/comment'; $postargs = array( 'user' => 'aardalich', 'pass' => 'BluesPacer', 'content' => $content, 'attachment_1' => $attachment_1 ); // 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); print_r($response); curl_close($session); ------- Expect I'm not grabbing the raw file correctly, or encoding it or something. Unsure of how. I was thinking the other way I could go is (after creating the ticket and getting the number from the response back) is to then send in an email with the attachment with the correct subject so it lands in the ticket. Thanks, Alex -----Original Message----- From: rt-users-boun...@lists.bestpractical.com [mailto:rt-users-boun...@lists.bestpractical.com] On Behalf Of Thomas Sibley Sent: Thursday, 29 March 2012 12:08 AM To: rt-users@lists.bestpractical.com Subject: Re: [rt-users] 4.0.5 REST - adding an attachment - php On 03/28/2012 02:07 AM, Alex Ardalich wrote: > Adding an attachment has me baffled. I understand I cannot do it at > ticket creation, need to do it as adding a comment. > I get as far as, Bad Request # No attachment for... > > If anyone has an example of how to do it I would be extremely grateful. http://wiki.bestpractical.com/view/REST#Ticket_History_Comment Without showing us what you're trying, we can do nothing but guess. My guess is that you're not POSTing the attachment_1 field.