Add a note to a FD Ticket via PHP

Hello ,

we want to add a note to an existing ticket via PHP and the FD API (code below).

This works so far so good, but we also want to change the status of the ticket.
But if I add the status filed to the request I get:

{“description”:“Validation failed”,“errors”:[{“field”:“status”,“message”:“Unexpected/invalid field in request”,“code”:“invalid_field”}]}

Any ideas?

Regards

Kalle

function FreshDeskAddTicketNote ($ticketID,$content)
{
               global $__apiKey;
               global $__password;
               global $__fdDomain;
               
               $ret=false;
               
               $ticket_data = json_encode(array(
                 "body" => $content,
                 "incoming" => false,
                 "private" => true,
                   "status" => 2,
               ));
 
               $url = https://$__fdDomain.freshdesk.com/api/v2/tickets/$ticketID/notes;
 
               $ch = curl_init($url);
 
               $header[] = "Content-type: application/json";
               curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
               curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
               curl_setopt($ch, CURLOPT_HEADER, true);
               curl_setopt($ch, CURLOPT_USERPWD, "$__apiKey:$__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);
 
               $code=$info['http_code']; 
               
 
               if($code == 200 || $code == 201) {
                              $ret=true; 
               }
               else
               {
               
                              echo ("<br>code: $code");
                              echo "Response Headers are \n";
                              echo $headers."\n";
                              echo "Response Body \n";
                              echo "$response \n";
                              
               }
 
 
               curl_close($ch);
               return $ret;
}

Hi @kalle_s

Good Day and welcome to the community.

In order to update the status of ticket you should use Update Ticket API. Add note API used by you is used to add note to existing ticket.

Hi Sachin, thanks for your quick reply,
as I wrote above, I want to add a note to an existing ticket.
Regarding to the api doc, this should be possible…or do I need a second call to the update ticket api?

Hi @kalle_s

You would need 2 API calls.

To add the note, please use ADD Note API which you are already using.
To update the status of ticket, please use Update Ticket API.

OK, problem solved. Thanks.

But regarding to the doc, this should be possible in one call or am I wrong?