I'm working on a file upload of an image with a registration form. The file is being passed to PHP correctly, and I can check its properties in the $_FILES variable. I used the API Explorer to get the code example below. This question (Uploading files through the API) touches on this, but the answer just directs the person to the API Explorer.

$result['attachment'] = civicrm_api3('Attachment', 'create', [ 'name' => $name, 'mime_type' => $_FILES['image']['type'], 'entity_id' => $result['contact']['id'], 'field_name' => 'custom_3', 'content' => $_FILES['image'], ]);

The error I receive is: Mandatory key(s) missing from params array: 'id' or 'content' or 'options.move-file' but I have no idea what this means. content is set in the params. This API call happens after a working sequence of creating a Contact, Address, Email, Websites, and more for the signup. I can find no other guidance on completing this.

1 Answer 1


"content" needs to be a string if using that - it represents the actual attachment contents. What you probably want is the move-file one. If you're at /civicrm/api in the explorer click on the Code Docs tab at the top and pick Attachment for the Entity, then at the bottom of the text that appears is an example, just yours is slightly different since it's a custom field.

Also some assorted samples in here, e.g. https://github.com/civicrm/civicrm-core/blob/5.14/tests/phpunit/api/v3/AttachmentTest.php#L91

  • 1
    Thanks for your guidance. I suspected something was up with the 'content' parameter because all the examples showed text. It would be helpful if the documentation actually said a bit more in most places... used 'options' => [ 'move-file' => $_FILES['image']['tmp_name'] ]
    – repertor
    Jun 29, 2019 at 3:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.