Using "custom_fields" and "cc_emails" When Creating Tickets Using the New V2 API

I am using PHP CURL to call the create ticket endpoint on the new V2 APIs.  I am creating tickets using the POST /api/v2/tickets endpoint.  I am able to create new tickets as long as I don't include the cc_emails key in the parameters I send to the API.  The following params work:

 

$params = array(
'email' => $email,
'subject' => $subject,
'description' => $description,
'priority' => $priority,
'status' => 2
);

 

But as soon as I add the cc_emails key / value pair, I get a 500 message from the Freshdesk servers:

 

 

$params = array(
'email' => $email,
'subject' => $subject,
'description' => $description,
'priority' => $priority,
'status' => 2,
'cc_emails' => array('peter@pointivo.com')
);


The same error occurs if I try to add custom_fields to the parameters

$params = array(
'email' => $email,
'subject' => $subject,
'description' => $description,
'priority' => $priority,
'status' => 2,
'custom_fields' => array('user_id' => 1)
);

What's the right syntax to use in these scenarios?

1 Comment

Hi Peter,

Thank you for trying out the new beta version of the Freshdesk API!


The Create Ticket API Endpoint expects the 'cc_emails' field to be an array in the format,

["sample1@freshdesk.com", "sample2@freshdesk.com"]


From your first example I can see that, the parameters that are received by the Freshdesk servers would look something like, 

  

{
"email"=>"peter@pointivo.com", 
"subject"=>"bombwindow", 
"description"=>"youare maa", 
"priority"=>2, 
"status"=>2, 
"cc_emails"=>{"0"=>"peter@pointivo.com"}
}

   


while the expected format is,

  

{
"email"=>"peter@pointivo.com", 
"subject"=>"bombwindow", 
"description"=>"youare maa", 
"priority"=>2, 
"status"=>2, 
"cc_emails"=>["peter@pointivo.com"]
}

  

 


Regarding your second query about custom fields,


The Create Ticket API Endpoint expects the 'custom_fields' field to be a key-value pair, whose keys should include only valid field names that are defined in your helpdesk. You can get info regarding the custom field names by accessing the List All Ticket Fields API Endpoint


For example if your List All Ticket Fields API Endpoint returns, 

 

[ ...,
  {
    "id" : 20,
    "description" : "",
    "label" : "number_custom",
    "name" : "number_custom_1",
    "position" : 3,
    "type" : "custom_number",
    "label_for_customers" : "number_custom",
    "default" : false,
    "required_for_closure" : false,
    "required_for_agents" : false,
    "required_for_customers" : false,
    "customers_can_edit" : true,
    "displayed_to_customers" : true,
    "created_at" : "2015-06-16T14:06:52Z",
    "updated_at" : "2015-06-16T14:06:53Z"
  },
  ...
]

 


then your input for creating the ticket should be something like,

 

{
"email"=>"peter@pointivo.com", 
"subject"=>"bombwindow", 
"description"=>"youare maa", 
"priority"=>"2", 
"status"=>"2", 
"custom_fields"=> {
  "number_custom_1"=>1
 }
}

 

 



Login or Signup to post a comment