Question

PHP Reply to Ticket (as client)

  • 10 April 2022
  • 0 replies
  • 92 views

Hello,

I am building a full integration of Freshdesk into a custom CRM I have built. I have managed to integrate various APIs but I am struggling with the “Reply as Customer” part.

Here is my code:

$body = $_POST['description'];
$requester_id = intval($_POST['requester_id']);
$post = json_encode(array(
'body' => $body,
'user_id' => $requester_id
));

$api_key = getenv("FRESHDESK_API");
$password = "x";
$yourdomain = getenv("FRESHDESK_DOMAIN");
$url = "https://".$yourdomain.".freshdesk.com/api/v2/tickets/".$id."/notes";
$ch = curl_init($url);
$header[] = "Content-type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_USERPWD, "$api_key:$password");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

$response = curl_exec($ch);
$decode = json_decode($response);
print_r($response);

curl_close($ch);

 The Requester ID is the same as the person who has created the initial ticket. I am not sure why but I keep getting this error.

{"code":"invalid_user","message":"You are not authorized to perform this action on behalf of this user. id:THERE_IS_A_ID_HERE, name:THERE_IS_A_NAME_HERE"}

I am guessing this is clashing with the API Key that I am using. 

What API do I use to reply as a Customer?

My workflow:
1. Customer logs in to my CRM.
2. Creates ticket
3. Gets notified of new replies from Support Team
4. Wants to reply back to the replies he has received from Support Team.

BTW - I also tried using the /reply endpoint & the reply is saved by the Name of the owner of API key.

 

Could someone please point me in the right direction?


0 replies

Join the Community or User Group to Participate in this Discussion

Reply