Skip to main content

FreshDesk API with PHP


Hello guys,



premise: I read all the support pages without finding a solution! :)I wanted info on the use of an API in PHP
I need to figure out how to insert a ticket into the system via API


<?PHP

$email = "email_fresh_desk@mail.com";
$password = "password";
$key = "api key"; // (This parameter is used?)
$urltopost = "https://my_portal.freshdesk.com/helpdesk/tickets.xml";
$datatopost = "
<helpdesk_ticket>
<description>Ticket test API!!!</description>
<subject>Test ticket creation api</subject>
<email>email_user@mail.com</email>
<priority>1</priority>
<status-name>Open</status-name>
<status>2</status>
<source>3</source>
</helpdesk_ticket>";

$ch = curl_init ($urltopost);
//curl_setopt($ch, CURLOPT_POST, true); // (This parameter is used?)

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_USERPWD, "$email:$password");
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/xml"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $datatopost);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // (This parameter is used?)
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // (This parameter is used?)
curl_setopt($ch, CURLOPT_KEYPASSWD, $key);
$returndata = curl_exec($ch);

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

?>

My problem is that I get blank page and the ticket is not entered!
I tried to do other combinations but do not get any positive result



Best regards!



Luca D.
Did this topic help you find an answer to your question?
This topic has been closed for comments

3 replies

Did you ever get it to work?

I have been looking for away to import all the ticket from our old custom made system to Freshdesk, but I haven't been able to automate this.


If you go it to work, I would appreciate if you could post it here how you did it.


Thanks :)


Regards,

Leonardo


  • Community Debut
  • 1 reply
  • July 3, 2013

Blake Robertson provides some working code at the bottom of this support ticket: https://support.freshdesk.com/support/discussions/topics/775


aravind.sundararajan
Skilled Expert
Forum|alt.badge.img+12

Hello,


You can find some sample repos here : https://github.com/freshdesk/fresh-samples/tree/master/PHP


Cheers!