Freshdesk API - Ticket reply from user via custom APP not working

This is in reference to the the issue addressed in Freshdesk API flow for the continuous conversations from user via replying to a user ticket - #3 by Saif

I am also trying to post a reply to a thread from my app as an user but it gets posted as Admin.
The solution mentioned in the post does not work. Any idea where I might be doing wrong?


You might be making an API call with admin’s API key?

Hi Saif, I really appreciate your such a prompt reply.
I see just I API Key.
So how do I get a different api key?

1 Like

This is the code I am trying:
$api_key = FRESH_DESK_API;
$yourdomain = FRESH_DESK_DOMAIN;

$getpaentdetails = $this->ss_aw_parents_model->get_parent_profile_detailsbyid($parent_id);

			$parentemail = $getpaentdetails[0]->ss_aw_parent_email;			
			$contactdetailsary = $this->contact_details();
			$userid = "";
			foreach($contactdetailsary as $value)
				if($value['email'] == $parentemail)
					$userid = $value['id'];
			$ticketid = $inputpost['ticket_id'];
			$message = $inputpost['message'];
			$ticket_data = json_encode(array(
			  "body" => $message,
			  "user_id" => $userid
			$url = "https://$$ticketid/reply";

			$ch = curl_init($url);

			$header[] = "Content-type: application/json";
			$header[] = "Content-type: multipart/form-data";
			curl_setopt($ch, CURLOPT_POST, true);
			curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
			curl_setopt($ch, CURLOPT_HEADER, true);
			curl_setopt($ch, CURLOPT_USERPWD, "$api_key:$password");
			curl_setopt($ch, CURLOPT_POSTFIELDS, $ticket_data);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

			$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);
			if($info['http_code'] == 201){
				$responseary['status'] = 200;
				$responseary['msg'] = "Reply post successfully";
				$responseary['status'] = 500;
				$responseary['error'] = $info;
				$responseary['msg'] = "Reply post fail";

$userid is the customer id in freshdesk server. This is the user in our app.
api key is the only API key I get from my Profile in freshdesk account.
If that is admin API key, then as you mentioned I am not aware of any other API key. Can you please suggest where do I get that to post a reply as an user.

Thanks in Advance.

Hello @deepanjandas
First, let us welcome you to the Freshworks community :tada:
Thank you for reaching out with your question and additional details about what you are trying to achieve.

Every API Key is associated with a particular user in Freshdesk. Further, every user is associated with one or more Roles in Freshdesk, which define what the user can or cannot do within Freshdesk.

We aren’t familiar with how your application gets this $api_key parameter, but the API Key provided to this app must likely be one associated with an administrator, as @Saif hinted. Any changes made to Freshdesk using an API are always associated with the user whose API key was provided as authentication for the API request. In your case, you are seeing the ticket reply being created in the name of an administrator, likely because the $api_key provided to the app belongs to that administrator.

If you only plan to work with the Reply to Ticket API, you might be in luck, as noted in this solution from another thread.

If you plan to make other API calls as well, you likely have 3 options from here -

  1. Modify your app so that it asks for an API key from each user using the app, so that the API requests made by the app are always using the actual end-users API key.
  2. Create a new user just for this app, with a specific role and specific permissions required by this app, and use this user’s API key for the app. All replies will then show up in this user’s name so you know that the app created them.
  3. Continue using the admin’s API key for this app, and consider including additional text in the message if you would like to call out this was created by the app on behalf of the end-user.

All the best!


This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.