Leads API with 37Signals Highrise

From HubSpot API Documentation

Jump to: navigation, search

Contents

Background

The purpose of this page is to illustrate one possible way to integrate 37 Signals "Highrise" CRM with your HubSpot system using the Leads API. It's not the only way, and it's not guaranteed to match your specific needs, but it should provide useful details and examples for your reference.

37 Signals Highrise is a separate company and a separate product. HubSpot does not provide any kind of support, consulting, or guarantees with regards to Highrise. You need to know your own Highrise system and how it works in order to complete this integration.

Some Notes on Highrise

Highrise is somewhat different from traditional CRM systems in that as of this writing, custom fields and objects are not enabled. You have the ability to work with either person accounts or company accounts, but you cannot create custom objects in the system. To get around the issue of placing the HubSpot GUID onto the leads passed to Highrise, I've decided to place the GUID in the 'Background' field, which is typically used just for notes on a person record in Highrise.

Setup API User

In order to be able to access the Highrise RESTful API, you'll need to acquire your API key from the Highrise system. You can find this by logging into your Highrise portal, then clicking on the 'My Info' link at the top right hand side of the page, then clicking on the 'API Token' link. You'll also need the base URL for your Highrise portal. Typically this is in the format of '<yourcompany>.highrisehq.com' but it may vary in some instances.

Configuring the Integration Code

If you're going to follow this code sample closely for your own integration, there are exactly five (5) places where you're going to need to add your own credentials based on your Highrise URL and API token, and your HubSpot API key. These places are outlined in this file with <> brackets. They are also listed out below:

  1. Line 6 - Enter your HubSpot API key that you acquire from HubSpot.
  2. Line 40 - Enter your Highrise portal's base URL here that you get from Highrise.
  3. Line 42 - Enter your Highrise API Token. Please note, you should leave the 'X' that appears after the colon on this line as is.
  4. Line 91- Enter your Highrise portal's base URL here that you get from Highrise.
  5. Line 95 - Enter your Highrise API Token. Please note, you should leave the 'X' that appears after the colon on this line as is.

Configuring Code to Run Periodically

This code snippet is intended to run on a web server by a job scheduler application such as CRON. We recommend configuring CRON to 'wake up' and run this script every 5-10 minutes in order to get new leads into Highrise as quickly as possible. For more information on CRON, please refer to the Wikipedia page here or the Unix manual page here.


<?php
//First, we start by opening the log file and getting the last time this file ran. $logfile = "hubspotLeadTime.log"; //Make sure you have the correct permissions on these log files on your server. $leadlog = "hubspotLeadLog.log"; $apikey = "XXXXXXXXXX"; //replace this with your own key
if (file_exists($logfile)) { //Proceed like normal
$fileh = fopen($logfile, 'r') or die("can't open file"); $oldtime = fread($fileh, filesize($logfile)); fclose($fileh);
//We're then going to Log the current time, then place it into our log file, overwriting the old time to prevent the log file growing huge... $newtime = time(); $passedtime = $newtime*1000; $fileh = fopen($logfile, 'w') or die("can't open file"); fwrite($fileh, $passedtime); fclose($fileh); }
else { //Create the file and place the first timestamp in there.
$newtime = time(); $passedtime = $newtime*1000; $fileh = fopen($logfile, 'w') or die("can't open file"); fwrite($fileh, "".$passedtime."\n"); fclose($fileh); }
//GET request to get leads form HubSpot SINCE the $oldtime in the log file. $jsonurl = 'https://hubapi.com/leads/v1/list/' . '?hapikey=' . $apikey . '&startTime=' . $oldtime; //replace the hapikey key with your own here! $json = file_get_contents($jsonurl,0,null,null); $json_output = json_decode($json,true);
foreach ($json_output as $lead) { //cycle through the array (lead points to the array...)
//Search Hughrise for leads with email matching lead's email from HubSpot. Since we can't properly store GUID in Highrise, we'll only de-dup by email $cl = curl_init(); curl_setopt($cl, CURLOPT_URL, "http://<YOUR COMPANY>.highrisehq.com/people/search.xml?criteria[email]=$lead[email]"); curl_setopt($cl, CURLOPT_RETURNTRANSFER, true); curl_setopt($cl, CURLOPT_USERPWD, "<Your Highrise API Token>:X"); $result = curl_exec($cl); curl_close($cl);
if (preg_match("/nil-classes/i", $result)) { //"nil-classes" is part of the XML that gets returned in the empty person record by Highrise. //process the lead and pass it into Highrise...
//This will build the XML string that gets passed into. Note the 'guid' in the background field. $xml = " <person> <first-name>$lead[firstName]</first-name> <last-name>$lead[lastName]</last-name> <title>$lead[jobTitle]</title> <background>Found Site Via: $lead[fullFoundViaString]\n First Visit: $convertDate\n HubSpot Lead Grade: $lead[score]\n Lead in HubSpot: $lead[publicLeadLink]\n Number of Conversion Events: $lead[numConversionEvents]\n UserToken: $lead[userToken]\n IP Address: $lead[ipAddress]\n HubSpot Guid: $lead[guid]</background> <visible-to>Everyone</visible-to> <contact-data> <email-addresses> <email-address> <address>$lead[email]</address> <location>Work</location> </email-address> </email-addresses> <phone-numbers> <phone-number> <number>$lead[phone]</number> <location>Work</location> </phone-number> </phone-numbers> <addresses> <address> <city>$lead[city]</city> <country>$lead[country]</country> <state>$lead[state]</state> <street>$lead[address]</street> <zip>$lead[zip]</zip> <location>Work</location> </address> </addresses> <web-addresses> <web-address> <url>$lead[website]</url> <location>Work</location> </web-address> </web-addresses></contact-data> </person>";
//cURL this XML into Highrise to create the new person record. $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "http://<YOUR COMPANY>.highrisehq.com/people.xml"); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/xml')); curl_setopt($curl, CURLOPT_POSTFIELDS, $xml); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_USERPWD, "<Your Highrise API Token>:X"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($curl); $http_code = curl_getinfo($curl ,CURLINFO_HTTP_CODE); curl_close($curl);
//Write to the log file saying we created the new lead in Highrise. if ($http_code == "201") { //If lead creation succeeded, HTTP 201 is returned, so log successful lead creation. $logleadlang = "".$http_code. " Created Lead with GUID: ".$lead[guid].""; $logs = fopen($leadlog, 'a') or die("can't open file"); fwrite($logs, $logleadlang); fclose($logs); }
else { //If lead creation failed, log the failure and the guid for the lead that didn't get entered. $failedlang = "Lead creation failed for GUID: " .$lead[guid].""; $logs = fopen($leadlog, 'a') or die("can't open file"); fwrite($logs, $logleadlang); fclose($logs); }
}
else {
break; //lead's email address was found, exit loop and stop...
} }
?>

Personal tools