freshworks / fresh-samples

Samples of code created by freshdesk
184 stars 181 forks source link

PHP Attatchment with Custom field #50

Closed thamudi closed 6 years ago

thamudi commented 6 years ago

Not an issue, more of an approach to a problem I got into. I have spent some time trying to figure out how to send an attachment along with custom fields without json encoding the whole array due the attachment getting not recognized:

<?php
 'email' => $email,
  'subject' => $subject,
  'description' => $txtMessage,
  'priority' => 2,
  'status' => 2,
  'custom_fields[fieldOne]'=> $One ,
  'custom_fields[fieldTwo]'=> $Two,
  'custom_fields[fieldThree]'=> $Three ,
'attachments[]' =>  curl_file_create("$pathToFile","$mimeType","$fileName") 

Note: I have tried working with: 'attachments'=>array('attachment_url'=>$pathToFile,'content_type'=>$mimeType,'name'=>$fileName'

I kept getting the following error message: Error Message: {"description":"Validation failed","errors":[{"field":"attachments","message":"Value set is of type key/value pair.It should be a/an Array","code":"datatype_mismatch"}]}