Invalid user error

hi, i am trying to reply on a ticket through the API and suddenly i am getting error that 
{"code":"invalid_user","message":"You are not authorized to perform this action on behalf of this user. id:43004366839, name:Sora"} although this is user is an activated user of freshdesk, please need assistance on that


Hello Zain,


Can you please help us with the Freshdesk account in which you're trying to construct the reply? The API call works only when the agent has the permission to assume the identity of the user. If you're trying this on an account with free Sprout plan, I'm afraid it wouldn't work as the Sprout plan doesn't have the "Assume Identity" feature.


Cheers!

yes @Aravind it is the same sprout account but few days back even it sprout account the reply was working fine, suddenly it stops working


Zain,


The reply API would work but it would log the reply on behalf of the user whose API key is used for authorisation. For sending replies as another user, you would require the "Assume Identity" feature.


Cheers!

Araving S,

yes i am replying with the same user who created the ticket with the same API but still i am getting this error. as mentioned in the above the user "Sora" created a ticket and with the same user (Sora) is replying back to the agent.


 

$reply_data = json_encode(array(
"body" => "Thanks Admin, i am waiting for your good response ...",
"user_id" => 42002034395,
));

$url = "https://$yourdomain.freshdesk.com/api/v2/tickets/12/reply";;

$ch = curl_init($url);

$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, $reply_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 = $server_output;

if($info['http_code'] == 201) {
echo "Reply has been posted, the response is given below."."<br>";
echo '<pre>', print_r(json_decode($response));
} else {
if($info['http_code'] == 404) {
echo "Error, Please check the end point \n";
} else {
echo'<pre>';print_r($response);
}
}

curl_close($ch);

 here is the code, please guide me if there is any code error

Sorry if my previous reply wasn't clear enough. In Sprout plan, you'd be able to send replies only as the current user ie. the agent whose API key is used in the request. You'll not be able to mask the identity of another user since the feature is not supported in the free sprout plan.


Cheers!

But it was working fine few days back with the same code even though the account was sprout,i am confused because it stop working suddenly. the API key you are talking about is the same we get in the profile settings of the domain . right?


let me add one more thing if it helps you out to understand my issue, right now i am not having any other Agent just the admin, And the admin is the one who is facilitating the tickets on my trail account


Yes, Zain. You're right - the API key is required for authenticating the request and it looks like you're using an admin API Key. This would allow you to use the reply API endpoint and send a response on a ticket. 


The difference here is that, you can send replies as the admin user but cannot pass the user ID value in the API call. This means that you're responding to the ticket as another user (Assuming the identity). This is possible in all plans starting from Blossom whereas it is not available in Sprout.


In all, the sprout plan allows you to send replies as yourself and not any other user.


Cheers!

Login or Signup to post a comment