I see this in the API documentation :
The Content-Type should always be multipart/form-data for create/update requests with attachments.
So, I think it's not possible
Hello Hugo,
Did you get a chance to look at our Github repo? This sample written in php might help you to achieve this.
Cheers!
Hello Aravind,
Thanks for your solution.
I am now stuck to create a new ticket with multiple files.
In my parameters :
array (size=9)
'custom_fields' =>
array (size=2)
'cf_order_number' => string '1772684' (length=7)
'cf_model' => string '2913711' (length=7)
'subject' => string 'Sinister' (length=8)
'description' => string '785785' (length=6)
'email' => string 'test@ŧest.com' (length=24)
'priority' => int 1
'status' => int 2
'attachmentss0]' => string '@/filer/data/upload/fo/912616/74fa5e2cbcff35860eea50b1575d4017.jpg' (length=66)
'attachmentss1]' => string '@/filer/data/upload/fo/912616/b9121362d89879fc15c22bae3be077d0.jpeg' (length=67)
'attachmentss2]' => string '@/filer/data/upload/fo/912616/e241ae160115a325bb2fb50cdfc5bdb5.jpg' (length=66)
The return message is :
public 'message' => string 'We're sorry, but something went wrong.' (length=38)
"attachmentss]" can only be a String, by I need to send several images.
Do you have a solution ?
Thank you in advance.
Regards,
Hugo
Hello Aravind,
I found the solution but I think it's impossible in Json to send more of 1 file :
$data = "";
$eol = "\r\n";
$mime_boundary = md5(time());
foreach ($params as $key => $value) {
// Attachments
if ($key == "files") {
foreach ($value as $key => $file) {
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Disposition: form-data; name="attachments[]"; filename="' . $file['name'] . '"' . $eol;
$data .= "Content-Type: " . mime_content_type($file['path']) . $eol . $eol;
$data .= file_get_contents($file['path']) . $eol;
}
} else {
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Disposition: form-data; name="' . $key . '"' . $eol . $eol;
$data .= $value . $eol;
}
}
$data .= "--" . $mime_boundary . "--" . $eol . $eol;
$header[] = "Content-type: multipart/form-data; boundary=" . $mime_boundary;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_USERPWD, "$apiKey:$password");
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
Regards,
Hugo
@Hugo.pascal thx for solution but how can I submit custom fields along with multiple attachments?
I have this error "[field] => custom_fields [message] => Value set is of type String.It should be a/an key/value pair [code] => datatype_mismatch )" here is my $params
$params = array(
'email' => $email,
'subject' => $subject,
'description' => $description,
'type' => $type,
'priority' => $priority,
'status' => 2,
'files' => $uploaded_files,
'custom_fields' => array("cf_product" => $product)
);
I am trying to create a ticket with attachments from the browser , I get the same error ===>
>field] => custom_fields message] => Value set is of type String.It should be a/an key/value pair code] => datatype_mismatch )