I am new to CiviCRM and did not find any answer to this.

I have a form on a Drupal page, and want to give ability to upload an image file in both Drupal and CiviCRM from within this form.

I use the "Attachment" api function. When saving the Drupal node, I call civicrm_api3('Attachment', 'create', params) and pass file params as well as entity_id and custom field_name as explained in the api explorer. The CiviCRM field is a file custom field and the entity is an event.

Here is the code I use :

$result = civicrm_api3('Attachment', 'create', array( 'debug' => 1, 'sequential' => 1, 'name' => $file->filename, 'mime_type' => $file->filemime, 'entity_id' => $event_id, 'field_name' => $field_name,//custom_14 'url' => file_create_url($file->uri), 'path' => drupal_realpath($file->uri), ));

I finally catch this error (look at {main} at the end):

20 {main} [is_error] => 1 [error_message] => Failed to run permission check: Unrecognized target entity table (civicrm_event) )

Guess I missed something, but what ? Any suggestion ?

Thanks for your help


1 Answer 1


Do you have created the custom field on event?

I would suggest you to add manually (via the UI) an attachement and check how it looks like (using the api explorer and get the file(s)), it will be easier to understand what civi expects by looking at what it does

  • 1
    Thanks for your suggestion. I did it and it showed me that Attachment API is not compliant with civievent. Attachment needs a reference to the object to whose attach the file and event table is not understood as a compliant table. It is restricted to Activity and Mailing only. This seems to explain the permission error. Actually, I have to use the File API to create an image attached to an event.
    – philippe
    Commented Feb 11, 2016 at 10:11

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.