Last active
October 13, 2015 02:28
-
-
Save ataylorme/4124988 to your computer and use it in GitHub Desktop.
Wufoo WebHook script to add lead to Zoho CRM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//verify handshake key | |
if( $_POST['HandshakeKey'] == 'ENTER YOUR HANDSHAKE KEY HERE' ): | |
//define $zoho_api_key | |
$zoho_api_key = "ENTER YOUR ZOHO API KEY HERE"; | |
//define $data | |
$data = array (); | |
/* If post data is received for a Wufoo field store it in the $data array */ | |
//first name | |
if(!empty($_POST['Field1'])) | |
$data['fname'] = $_POST['Field1']; | |
//last name | |
if(!empty($_POST['Field2'])) | |
$data['lname'] = $_POST['Field2']; | |
if(!empty($_POST['Field3'])) | |
$data['email'] = $_POST['Field3']; | |
//phone | |
if(!empty($_POST['Field4'])) | |
$data['phone'] = $_POST['Field4']; | |
//message | |
if(!empty($_POST['Field5'])) | |
$data['description'] = $_POST['Field5']; | |
/* additional fields for Zoho */ | |
//source | |
$data['source'] = 'mywebsite.com Contact Form'; | |
//owner - email address of Zoho user who will own the lead | |
$data['owner'] = '[email protected]'; | |
/* loop through each data value and wrap it in XML markup */ | |
//start lead container | |
$zoho_xml_data = '<Leads><row no="1">'; | |
foreach($data as $key => $value): | |
switch($key): | |
case 'description': $wrapper = '<FL val="Description">'; break; | |
case 'source': $wrapper = '<FL val="Lead Source">'; break; | |
case 'fname': $wrapper = '<FL val="First Name">'; break; | |
case 'lname': $wrapper = '<FL val="Last Name">'; break; | |
case 'email': $wrapper = '<FL val="Email">'; break; | |
case 'phone': $wrapper = '<FL val="Phone">'; break; | |
case 'owner': $wrapper = '<FL val="Lead Owner">'; break; | |
endswitch; | |
if($wrapper) | |
$zoho_xml_data .= $wrapper . $value . '</FL>'; | |
endforeach; | |
//end lead container | |
$zoho_xml_data .= '</row></Leads>'; | |
//define $zoho_url. note: XML data needs to be url encoded | |
$zoho_url = "https://crm.zoho.com/crm/private/xml/Leads/insertRecords?newFormat=1&authtoken=" . $zoho_api_key . "&scope=crmapi&xmlData=" . urlencode($zoho_xml_data); | |
//define cURLzoho function | |
function cURLzoho($url) { | |
$ch = curl_init(); | |
$timeout = 5; | |
curl_setopt($ch,CURLOPT_URL,$url); | |
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); | |
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); | |
$data = curl_exec($ch); | |
curl_close($ch); | |
return $data; | |
}//end cURLzoho function | |
//store response from Zoho | |
$response = cURLzoho($zoho_url); | |
/* store the response to a log file. once leads are being captured in Zoho you can comment this out */ | |
file_put_contents('zohoResponse.log', $response . "\n\n", FILE_APPEND | LOCK_EX); | |
endif; //end handshake if | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you need a detailed explanation on how to use this script check out my blog post