Using CiviCRM fields in MailChimp

dewolfe001's picture

I have a Drupal 7.21 / CiviCRM 4.2.2 install.
It uses CiviCRM, MailChimp and Profile2. I need to put the first name and last name from a CiviCRM contact into the MailChimp for the mailouts. What I planned on using to make the linkage is Custom Token. I didn't want to write a custom module to pull this off if Custom Token were available to do almost the same job.

Here is what I built:

if (module_exists('civicrm')) {
$user = user_load(arg(1));


$userID = civicrm_uf_match_id_get( $user->uid );

$retrieve = array( contact_id => $userID  );

$getContact = civicrm_contact_get( $retrieve );
$bits = array_shift($getContact);  

My questions:
- Is there an even leaner way to pull this off? That is, get the contact fields into Drupal's install of MailChimp?
- How do I pass the UID reference to the Custom Token so that it knows to look up and produce the relevant CivCRM record?

Thanks in advance,



There are really 2 questions

kreynen's picture

There are really 2 questions here...

  1. How to expose token values from CiviCRM to Drupal?
  2. Ways to integrate Drupal/CiviCRM w/ MailChimp?

Unfortunately I think the answers to Q2 will likely make solving the CiviCRM tokens issue a moot point for you. Still something I'd like to find a good solution for. I spent some time working with tokens before updating If it turns out there is a reason to manage MailChimp from the Drupal side of your configuration, you might want to look at the function to convert Drupal username to CiviCRM Contact name...

Similar logic to what you wrote, but using version 3 of the api. CiviCRM Realname automatically replaces the Drupal username anywhere hook_username_alter() is used.

For Q2, I'd like to know why you're trying to integration MailChimp on the Drupal site? Why not manage that in CiviCRM where all you contact values would be available? Have you looked at...