I'm stumped with this particular Feed import problem.

I've got a content type (node) that has an entity reference field that relates it to an number of CiviCRM organization contacts. When you manually create a node, the entity reference field auto-completes the field and if you look at it in the editing view, you see the name of the contact along with their CiviCRM unique contact id. It would look like the following:

Contact Name [cid:8]

In the regular view, you just see the Contact Name.

I figured I could use Drupal Feeds and Feeds Tamper and then create a CSV import but I can't seem to format the entity reference field correctly so that the data is accepted. I've tried setting it to "Organization Name" as well as "id" and "user_unique_id". I've fed it straight integers for id and the unique id and I've tried "Contact Name [cid:8]" as well as just the contact name or just the "[cid:8]" part and nothing seems to stick. The content is created but the entity reference field remains empty. I can of course manually enter the values but that defeats the point of the import.

Any ideas?

These are the pertinent parts of the site:

  • Drupal 7.x
  • CiviCRM 4.4.x
  • Feeds
  • Feeds Tamper
  • Entity
  • CiviCRM entities
  • Entity Reference
  • CiviCRM Contact Reference Field

Thanks, Andrew

2 Answers 2


Not sure if https://www.drupal.org/project/civicrm_user_reference will work for you, but I wrote that when having issues with CiviCRM Contact Reference Field in another use case.

  • Thanks Kevin, That might be just what I need. I'll give it a spin and see if it helps. Apr 16, 2015 at 15:32
  • After some tinkering with the CiviCRM User Reference field, I don't think it's going to do what I want because the CiviCRM contacts that I'm referencing in this case aren't Drupal users and I don't know if I want them to be. If I make them users it may clutter up my user admin. I'll have to give it some more though before deciding. Jun 2, 2015 at 0:36
  • Ok, I've changed my mind... The CiviCRM User Reference Field module rocks and I don't think there is any better solution (at least at the moment). Thanks a million for a) creating it and b) suggesting it as a viable solution. It works great! Jun 2, 2015 at 1:39

Ok, we finally have a solution to this one. Unfortunately I wasn't able to make use of the CiviCRM User Reference field but familiarizing myself with it was a good exercise anyway. I am certain I will use it elsewhere.

Ours is a pretty specific use-case so it's unlikely that the majority of Drupal developers will run into this issue but nonetheless, in case someone else does, here are the details.

We have a content type that contains one or more values of a CiviCRM Contact (Organization Name) and we are using the CiviCRM Contact field in our content type to collect/render those values.

Here's the catch and the why Feeds on its own can't handle importing to the CiviCRM Contact field. The value that the CiviCRM Contact field holds isn't the Organization Name, it's the Contact ID (cid). The CiviCRM Contact field does all of the behind scenes voodoo to interpret String to CID and CID to String and the Feeds module isn't privy to the process because Feeds doesn't have access to the CiviCRM API. Once we figured this out (and it took a while), the solution wasn't really that difficult.

We required two Feeds helper modules: Feeds Tamper and Feeds PHP Tamper

Feeds Tamper enabled us to add a "plugin" that intercepts the CSV values we are importing and pre-process them before handing them off to Feeds to insert the values in the appropriate fields. Feeds PHP Tamper allows us to run PHP code in our preprocessing plugin.

Our solution required us to expose the CiviCRM API to Drupal in a Feeds Tamper PHP "plugin" and then use it to lookup by Organization name and return the CID while we looped through the contents of the CSV file cell. The following is a proof of concept we came up with while working on this:

  civicrm_initialize(); // Expose the CiviCRM API to Drupal

  function cid_lookup($name) {
    $params = array(
      'version' => 3,
      'organization_name' => $name,
    $result = civicrm_api('Contact', 'get', $params);
    return $result['id'];

  $organization_name = 'ACME Company';
  $organization_cid     = cid_lookup($organization_name);
  print "The ID for $organization_name = $organization_cid";

Hopefully this comes in handy for someone else too.

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.