Skip to content

Instantly share code, notes, and snippets.

@rothschild86
Created May 12, 2016 01:46
Show Gist options
  • Save rothschild86/9c7530e82d9b750a58779cc4e4625769 to your computer and use it in GitHub Desktop.
Save rothschild86/9c7530e82d9b750a58779cc4e4625769 to your computer and use it in GitHub Desktop.
Caldera Forms to HubSpot CRM integration
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.
//required plugins: code snippets, caldera forms, caldera forms run action
add_action('consult_req_submitted', 'consult_req_submitted_sync_hubspot');
function consult_req_submitted_sync_hubspot( $data ){
$hubspot_api_key = 'ffffffff-27a0-4591-9b68-27d4bb31ed76';
$hubspot_list_id = '1'; //optional
$caldera_name = $data[ 'your_name' ]; //this is the caldera field slug
$caldera_email = $data[ 'email' ]; //this is the caldera field slug
$caldera_phone = $data[ 'telephone' ]; //this is the caldera field slug //change caldera mask to 999-999-9999
$data = array('properties' => array());
$data['properties'][] = array('property' => 'firstname', 'value' => $caldera_name);
$data['properties'][] = array('property' => 'email', 'value' => $caldera_email);
$data['properties'][] = array('property' => 'phone', 'value' => $caldera_phone);
//$data['properties'][] = array('property' => 'lastname', 'value' => $caldera_lastname);
try {
$hubspot_url = 'https://api.hubapi.com/contacts/v1/contact/createOrUpdate/email/'.$caldera_email.'/?hapikey='.rawurlencode($hubspot_api_key);
$curl = curl_init($hubspot_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FORBID_REUSE, true);
curl_setopt($curl, CURLOPT_FRESH_CONNECT, true);
//curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
//second call is optional
$hubspot_url = 'https://api.hubapi.com/contacts/v1/lists/'.$hubspot_list_id.'/add/?hapikey='.rawurlencode($hubspot_api_key);
$data = array('emails' => array($caldera_email));
$curl = curl_init($hubspot_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FORBID_REUSE, true);
curl_setopt($curl, CURLOPT_FRESH_CONNECT, true);
//curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
} catch (Exception $e) {
}
}
@Pierre0002
Copy link

Hi.
I'm trying to understand the usage of your code :).
So, do I have to install the plugin "caldera forms run action" then add a Processor, set its "Position" to Post-Process", its "type' to "Action" and enter "consult_req_submitted" in the "Action / Filter" field to make it works?
That's it?

TIA.

Amicably,

Pierre.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment