freshworks / fresh-samples

Samples of code created by freshdesk
184 stars 181 forks source link

Creating ticket with attachments giving strange error #53

Open Zain-ulHassan opened 6 years ago

Zain-ulHassan commented 6 years ago

i am using PHP Version 7.2.2 and i am following this document https://github.com/freshdesk/fresh-samples/blob/master/PHP/create_ticket_with_attachment.php to create a ticket with attachment but i am getting this error Error, HTTP Status Code : 0 Headers are Response are .

Here is my code below

$ticket_payload = array( 'email' => $email, 'subject' => 'test', 'description' => 'testing description content', 'priority' => 2, 'status' => 2, 'attachments[]' => curl_file_create("data/butterfly.png", "image/png", "butterfly.png"), );

$url = "https://$yourdomain.freshdesk.com/api/v2/tickets"; $ch = curl_init($url);`

`$header[] = "Content-type: multipart/form-data";`

`curl_setopt($ch, CURLOPT_POST, false);`
`curl_setopt($ch, CURLOPT_HEADER, true);`
`curl_setopt($ch, CURLOPT_HTTPHEADER, $header);`
`curl_setopt($ch, CURLOPT_USERPWD, "$api_key:$password");`
`curl_setopt($ch, CURLOPT_POSTFIELDS, $ticket_payload);`
`curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);`

$server_output = curl_exec($ch); $info = curl_getinfo($ch); $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $headers = substr($server_output, 0, $header_size); $response = substr($server_output, $header_size);

am i doing something wrong ?