create ticket with attachments amd custom fields from ajax with php


Can anyone provide me code PHP code to create ticket with attachment and custom fields please.



This topic has been closed for comments

3 replies

Userlevel 4
Badge +12

Hello Ricardo,


Did you get a chance to brows through our PHP code samples listed in Github here?


Cheers!

Hello Aravind 


That's right, but I get an error with the code they have for example on github


That's right, but I get an error with the code that has an example in github, this is the error:


{"description":"Validation failed","errors":[{"field":"attachments[]","message":"Unexpected/invalid field in request","code":"invalid_field"}]}


and in my code i have this


$filename = $_FILES['file']['name'];

$filedata = $_FILES['file']['tmp_name'];

$filesize = $_FILES['file']['size'];


$custom_fields = array(

"cf_clasificacin" => $clasificacion,

);

$ticket_payload = json_encode(array(

"description" => $descripcion,

"subject" => $asunto,

"email" => $correo,

"priority" => intval($prioridad),

"status" => intval($estado),

"cc_emails" => array("ram@freshdesk.com", "diana@freshdesk.com"),

"custom_fields" => $custom_fields,

"attachments[]" => curl_file_create($filename, $mimetype, $filedata),

));