The WP Fusion CRM API

#Overview

WP Fusion takes a completely original approach to connecting WordPress to our supported CRMs and marketing automation systems. There is no other plugin available that is as flexible or extensible.

Normally, with a plugin like Gravity Forms (for example), you would download one of several available add-ons that connect Gravity Forms to your CRM of choice, like the ActiveCampaign add-on or AgileCRM add-on. These are created from scratch and use code unique to the API in question.

Before WP Fusion, many sites would have to use several different plugins to get a basic level of integration with their CRM. An ActiveCampaign user might need ActiveCampaign add-on for Gravity Forms, ActiveWoo to send WooCommerce order data, and the official ActiveCampaign plugin to enable site tracking and embedding forms.

This introduces a lot of unnecessary overlap, with the ActiveCampaign SDK being included multiple times, and redundant API calls being sent.

#How we solved that problem

When designing WP Fusion, we realized that all of these CRM systems offer the same basic functionality: adding new contacts, updating existing contacts, applying and removing tags, and loading contact data from the CRM.

So with that in mind, we created a wrapper class for each CRM, with a standardized set of functions to send and receive data from WordPress, then reformat it according to the rules of each API. Every one of our integrations has at least the following methods:

#connect()

wp_fusion()->crm->connect( $auth = null, $test = false );

The connect() function is called by all the member functions in the class to initialize the connection to the CRM. It’s not necessary to use this in your code, but it can be used to validate an API key or OAuth token by setting $test to true.

Parameters:

  • $auth (string) (Optional) The API key or other authorization code required to connect. There may be more than one parameter depending on the CRM. If this is left blank, WP Fusion will use the authentication data you entered on the original setup page.
  • $test (bool) (Optional) If set to true, WP Fusion will also verify the connection by attempting to make an API call.

Return values:

  • true (bool) If the connection was successful
  • $error (WP_Error object) If the connection was unsuccessful

#sync_tags()

wp_fusion()->crm->sync_tags();

Loads all available tags from the CRM and updates the available tags in the tag dropdowns for WP Fusion.

Return values:

  • $tags (array) An array of tags in the CRM
  • $error (WP_Error object) If the API call failed

#sync_crm_fields()

wp_fusion()->crm->sync_crm_fields();

Loads all available fields and custom fields from the CRM and updates the available fields in the dropdowns for WP Fusion.

Return values:

  • $crm_fields (array) An array of available fields in the CRM
  • $error (WP_Error object) If the API call failed

#get_contact_id()

wp_fusion()->crm->get_contact_id( $email_address );

Looks up a contact ID in the CRM by their email address.

Parameters:

  • $email_address (string) The email address to search for a contact by

Return values:

  • $contact_id (int) A contact ID for that email address
  • false (bool) If no contact ID was found with that email address
  • $error (WP_Error object) If the API call failed

#get_tags()

wp_fusion()->crm->get_tags( $contact_id );

Loads a contact’s tags from the CRM.

Parameters:

  • $contact_id (int) The contact ID to load tags for

Return values:

  • $tags (array) An array of tag IDs for the contact (or an empty array if no tags were found)
  • $error (WP_Error object) If the API call failed

#apply_tags()

wp_fusion()->crm->apply_tags( $tags, $contact_id );

Applies one or more tags to a contact.

Parameters:

  • $tags (array) An array of tags to apply
  • $contact_id (int) The contact ID to apply the tags to

Return values:

  • true (bool) The tags were successfully removed
  • $error (WP_Error object) If the API call failed

#remove_tags()

wp_fusion()->crm->remove_tags( $tags, $contact_id );

Removes one or more tags to a contact.

Parameters:

  • $tags (array) An array of tags to remove
  • $contact_id (int) The contact ID to remove the tags from

Return values:

  • true (bool) The tags were successfully removed
  • $error (WP_Error object) If the API call failed

#add_contact()

wp_fusion()->crm->add_contact( $contact_data, $map_meta_fields = true );

Adds a new contact to the CRM.

Parameters:

  • $contact_data (array) An associative array containing the data for the new contact, with the WordPress field as the key and the data as the value, like array( 'user_email' => '[email protected]' );
  • $map_meta_fields (bool) If set to true, WP Fusion will convert the field keys from WordPress meta keys into the field names in the CRM. Set to false to bypass this conversion.

Return values:

  • $contact_id (int) The contact ID for the newly created contact
  • $error (WP_Error object) If the API call failed or the data was rejected

#update_contact()

wp_fusion()->crm->update_contact( $contact_id, $contact_data, $map_meta_fields = true );

Updates a contact in the CRM.

Parameters:

  • $contact_id (int) The contact ID to update
  • $contact_data (array) An associative array containing the update data, in the same format as add_contact();
  • $map_meta_fields (bool) If set to true, WP Fusion will convert the field keys from WordPress meta keys into the field names in the CRM. Set to false to bypass this conversion.

Return values:

  • true (bool) The contact was successfully updated
  • $error (WP_Error object) If the API call failed or the data was rejected

#load_contact()

wp_fusion()->crm->load_contact( $contact_id );

Loads the contact record for a contact ID and returns an associative array of WordPress field / value pairs, based on the WP Fusion “Contact Field” settings.

Parameters:

  • $contact_id (int) The contact to load

Return values:

  • $user_meta (array) Array containing the contact data
  • $error (WP_Error object) If the API call failed or the contact was not found

#load_contacts()

wp_fusion()->crm->load_contacts( $tag_id );

Searches the CRM for any contacts with the specified tag and returns an array of contact IDs.

Parameters:

  • $tag (int or string) The tag to search by

Return values:

  • $contact_ids (array) Array of contact IDs returned by the search. Will be an empty array if no results were found
  • $error (WP_Error object) If the API call failed

See the next section for more information on how to utilize WP Fusion’s core helper functions while interfacing with your CRM.

Was this helpful?