Implementation using Rules (D7)

Last updated on
30 April 2025

You are browsing documentation for an older version of Drupal, which is not supported any longer, and the information may not be correct. See current documentation for Contributed modules

There are many ways that the Infusionsoft API module could be used in Drupal 7. Hopefully this will be helpful to you as you build your own implementation.

After installing and setting up the Infusionsoft API module, the first thing that needs to be done is to implement hook_infusionsoft_contact_alter in your own custom module.

Obviously you will need to change this to match your use case, but hopefully this example is thorough enough to help you. Be sure to change "mymodule" to the machine name of your custom module.

function mymodule_infusionsoft_contact_alter(&$contact, $account) {
  if ($account->uid) {
    $contact['_CustomFieldUserProfile'] = 'https://example.com/user/'.$account->uid;
  }
  if (!empty($account->field_first_name['und'][0]['value'])) {
    $contact['FirstName'] = $account->field_first_name['und'][0]['value'];
  }
  if (!empty($account->field_last_name['und'][0]['value'])) {
    $contact['LastName'] = $account->field_last_name['und'][0]['value'];
  }
  if (!empty($account->field_member_bio['und'][0]['value'])) {
    $contact['_MemberBio'] = strip_tags($account->field_member_bio['und'][0]['value']);
  }
  $family = profile2_load_by_user($account->uid, 'family');
  $contact_information = profile2_load_by_user($account->uid, 'contact_information');
  if ($contact_information) {
    $contact_address = field_view_field('profile2', $contact_information, 'field_ol_locator_address', 'value');
    if ($contact_address) {
      $contact['StreetAddress1'] = $contact_address['#items'][0]['thoroughfare'];
	  $contact['StreetAddress2'] = $contact_address['#items'][0]['premise'];
	  $contact['City'] = $contact_address['#items'][0]['locality'];
	  $contact['State'] = $contact_address['#items'][0]['administrative_area'];
	  $contact['PostalCode'] = $contact_address['#items'][0]['postal_code'];
	  $contact['Country'] = $contact_address['#items'][0]['country'];
    }
    $contact_phone = field_view_field('profile2', $contact_information, 'field_phone', 'value');
    if ($contact_phone) {
      $contact['Phone1'] = $contact_phone['#items'][0]['value'];
    }
  }
  if ($family) {
    $children_in_family = field_view_field('profile2', $family, 'field_children', 'value');
    if ($children_in_family) {
	  $children_rendered = drupal_render($children_in_family);
      $contact['_Children'] = strip_tags($children_rendered);
    }
    $member_family = field_view_field('profile2', $family, 'field_member_family', 'value');
    if ($member_family) {
      $contact['_FamilyInfo'] = strip_tags($member_family['#items'][0]['value']);
    }
	$marital_status = field_view_field('profile2', $family, 'field_member_marital_status', 'value');
	if ($marital_status) {
      $contact['_MaritalStatus'] = $marital_status['#items'][0]['value'];
    }
	$spouse_name = field_view_field('profile2', $family, 'field_spouse_name', 'value');
	if ($spouse_name) {
      $contact['SpouseName'] = $spouse_name['#items'][0]['value'];
    }
  }
}

With your contact information all properly mapped, contacts can now be added properly to Infusionsoft through the API. Now we need to setup some rules to tell Drupal when to update Infusionsoft information.

Adding Contacts to Infusionsoft

For a quick reference to some helpful rules that can be implemented in pretty much any configuration go to this page. Exports are provided on that page, while only explanations will be on this page.

The first rule you will likely need in any implementation is one that will create a contact in Infusionsoft. There may be a number of events you might use to add a new contact to Infusionsoft, but a common one would be on the creation of a new user account. In most cases no conditions are necessary. There are a two options for how to add a contact, I will explain them here:

  • Add a Contact - Will add a contact based on a Drupal user account. Use this option if you have a user object available to you.
  • Add a Contact to a Group by Email - Will search for an existing Infusionsoft Contact and add a Tag to that contact. If no contact already exists then a contact will be created and the tag will be added to the newly created contact. Use this option only if you do not have a user object available in your rule. (Available in dev as of June 21st)

After adding the contact using one of those two options you will then need to add the action "Opt in a Contact to the Email Service". If you do not add this action, the contacts you add to Infusionsoft will not be marketable!

Tagging

Once a contact is created you can then add tags to define the contact and add them to Infusionsoft campaigns. Here are some of the uses of tags:

With the Infusionsoft API module you are given these actions that allow you to add or remove tags in your rules:

  • Add a Contact to a Group
  • Remove a Contact from a Group
  • Add a Contact to a Group by Email
  • Remove a Contact from a Group by Email

Note that in a future release all references to the word "Group" will be changed to "Tag".

Please note how powerful the tagging system is. You can use it for all sorts of things including adding and removing contacts from lists and starting and stopping campaigns build with campaign builder. While adding and deleting contacts is important, tagging is how you interact with your contacts.

Deleting Contacts

Some use cases will not need to delete contacts from Infusionsoft, but for those who do need that option you can use these two rules:

  • Delete a Contact (Always use this option when possible)
  • Delete a Contact by Email

Help improve this page

Page status: Not set

You can: