I tried many things like base 64 or just using the php function file_get_contents
but when i check the civicrm UI and click on the attachment it doesn't work (for images for example it says unrecognized format).
So what is the proper way to use the content property in the create action in the API V3
1 Answer
There's a unit test at https://github.com/civicrm/civicrm-core/blob/3a822c76c86397199c53f750e71081d548f45a96/tests/phpunit/api/v3/AttachmentTest.php#L93-L100 and https://github.com/civicrm/civicrm-core/blob/3a822c76c86397199c53f750e71081d548f45a96/tests/phpunit/api/v3/AttachmentTest.php#L316-L319 that together describe how to use this. Putting them together it would be:
civicrm_api3('Attachment', 'create', [
'entity_table' => 'civicrm_activity',
'entity_id' => $activityId,
'name' => 'example.png',
'mime_type' => 'image/png',
'description' => 'My test description',
'options' => [
'move-file' => 'temporary/path/to/example.png',
],
]);
civicrm_file
you find no path column, instead you find the uri which is just the file name, then civicrm will do the rest and calculate the path depending only on the file name, at least that's what i understood.'options' => ['move-file' ...]
, which gets used in the api call here: github.com/civicrm/civicrm-core/blob/…