public
Last active

Wufoo WebHook script to add lead to Zoho CRM

  • Download Gist
wufoo-webhook-zoho-crm
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
<?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'];
 
//email
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'] = 'me@mywebsite.com';
 
/* 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
?>

If you need a detailed explanation on how to use this script check out my blog post

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.