Skip to main content

 Hello,

I am trying to post data into timesheet note.

This is what my code looks like

$data = array (
  'time_entry' => array (
  'note' => 'test via API',
  ),
);

$urltopost = "http://samplecompany.freshdesk.com/helpdesk/time_sheets/1111111.xml";
$headera] = "Content-type: application/xml";

$ch = curl_init ($urltopost);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt ($ch, CURLOPT_USERPWD, sampleuser:password);
curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);

try {
   $returndata = curl_exec ($ch);
   $e = curl_error($ch);
}
catch(Exception $e) {
   throw new Exception ('An error occured! '.$e->getMessage());
}


curl_close($ch);

echo "<pre>";
print_r ($returndata);
echo "</pre>";

I have tried this one with all little changes possible, f.e. without http_build_query etc.
Exaclty this one code I am using for GET with no problems.


Output on the page is :
We're sorry, but something went wrong.
We've been notified about this issue and we'll take a look at it shortly.

Any help?

Here's what works


curl -u mail:password -H "Content-type: application/xml" "<time

entry><user_id>11111</user_id><hours></hours><note>test

note</note></time_entry>" -X POST "http://xxx.freshdesk.com/helpdesk/tickets/7/time_sheets.xml"