Search code examples
phpzendesk-api

All fields data not submitting to zendesk ticket form via php api


I have integrated my website from with zendesk, I am following this api library, I am successfully creating tickets to zendesk but, The problem is I am not able to send all the form fields to zendesk ticket form. Only subject and description field data is sending through my code.

This is my web form This is my web form

This is my zendesk ticket form enter image description here

This is my zendesk ticket listing enter image description here

This is My code to create ticket

 public function CreateTicketOnZendesk($subject,$email,$description,$transactionNumber){
    try{
        $client = $this->zendesk();
             $newTicket = $client->tickets()->create([
                 'subject'  => $subject,
                 'comment'  => [
                     'body' => $description
                 ],
                 'custom_fields'=>[
                     'email'  => $email,
                     'transaction_number'  => $transactionNumber,
                 ],
                 'priority' => 'normal'
             ]);
             return true;
    }catch(\Exception $e){
        error_log($e->getMessage());
    }
 }

But cannot send the email and transaction number field data tried adding these field like sending subject as well.


Solution

  • Custom fields should be passed as id,value pairs try using this for custom_fields. To get fields id you can go to ticket fields panel on zendesk or can use this api api/v2/ticket_fields.json

     'custom_fields'=>[
                         [
                             'id'=> '<email_field_id>', 
                             'value'=> $email
                         ],
                         [
                             'id'=> '<transaction_number_field_id>',
                             'value'=> $transactionNumber
                         ]
     ],