Home » Blog » Using Wufoo WebHooks to add leads to Zoho CRM

Using Wufoo WebHooks to add leads to Zoho CRM

This is an advanced tutorial and assumes you are comfortable with PHP, Wufoo, and Zoho

If you are like me you love Wufoo for creating forms. Wufoo integrates with a lot of services out of the box but sometimes you need to integrate with an application that Wufoo doesn’t have built-in integration for. I recently had to put up a contact form onto a site that needed to integrate with Zoho CRM which isn’t a Wufoo partner. I used a Wufoo webhook to call a php script that creates a lead in Zoho and am going to show you how.

Create the Wufoo Form

For this tutorial we will be making a simple contact form. Create a new form in Wufoo. Set the form name, redirect url, etc. Add fields for Name, Email, Phone, and Message. Name, Email, and Message are required for our form. Save the form and click on “Setup email notifications for this form”.

Setup the webhook in Wufoo

The third box has a dropdown to add notifications to other applications. Select webhook and click “Add Integration”. The box will now have fields for webhook url and Handshake Key.

WebHook URL is the url to the script we will create.

Example: http://www.mysite.com/wufoo-zoho-webhook.php

WebHook Handshake Key is what will authenticate Wufoo’s webhook to our script. This should be a secure key with a mix of UPPER/lowe case letter, number, and symbols. I used a 25 digit randomly generated key.

Example: k]NSID,uB]b6#lO)g?kbptc5l

Writing the PHP script

Create a new file called “wufoo-zoho-webhook.php” (from our WebHook URL above).

Verifying the hadshake key

When the webhook sends data to our script it will be $_POST data. So here we are getting the posts Handshake Key and making sure it is the correct value. All of the code from this point on will go inside the IF statement.

[code language=”php”]
<?php
if( $_POST[‘HandshakeKey’] == ‘k]NSID,uB]b6#lO)g?kbptc5l’ ):
/* ALL OF OUR SCRIPT CODE WILL GO HERE */
endif; //end if handshake key
?>
[/code]

Define Zoho API key

Here is a quick quote from the Zoho API documentation about to how to get an API key if you do not have one.

Generating the API key (apikey)
Log in to Zoho Support (https://support.zoho.com) using administrator credentials
Click Setup>Developer Space
Click Generate API Key
Copy the API key that is generated. You will require this key to integrate Zoho Support with other third-party services.

We are just going to store the API key in a variable to use later.

[code language=”php”]
<?php
$zoho_api_key = “Enter your Zoho API key here”;
?>
[/code]

Capturing the form fields

You will need to reference the fields by API name. To find out the API names of our form fields visit your form list, find our form and click code. In the upper-right of the code screen you will see a button labeled “API Information”. Exactly what we need.

When posting data each field will have a key of “Field” plus the API ID. First Name in our example is “Field1”. Since we are not interacting with the Wufoo API you can ignore the Wufoo API key.

Here we are creating an array called “$data” and capturing our form $_POST data.

[code language=”php”]
<?php
$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 – no direct match in Zoho, sending message to the lead description field instead
if(!empty($_POST[‘Field5’]))
$data[‘description’] = $_POST[‘Field5’];
?>
[/code]

Additional fields for Zoho

Next we need to define lead source to pass to Zoho.

[code language=”php”]
<?php
//source
$data[‘source’] = ‘mywebsite.com Contact Form’;
?>
[/code]

Lead owner is optional. If you do not define lead owner it will default to the person who created the Zoho API key.

[code language=”php”]
<?php
//owner – email address of Zoho user who will own the lead
$data[‘owner’] = ‘me@mywebsite.com’;
?>
[/code]

Converting the data to an XML format Zoho can read

According to the Zoho API documentation our data needs to be in XML format setup similiar to the example below.

Add Records Demo
John
Customer Care
john@demo.com
002200330044

To acheive this we are going to loop through our data array and add XML markup.

[code language=”php”]
<?php
$zoho_xml_data = ‘<Leads><row no=”1″>’;

foreach($data as $key => $value):
switch($key):
case ‘description’: $zoho_xml_data .= ‘<fl val=”Description”>’ . $value . ‘</fl>’; break;
case ‘source’: $zoho_xml_data .= ‘<fl val=”Lead Source”>’ . $value . ‘</fl>’; break;
case ‘fname’: $zoho_xml_data .= ‘<fl val=”First Name”>’ . $value . ‘</fl>’; break;
case ‘lname’: $zoho_xml_data .= ‘<fl val=”Last Name”>’ . $value . ‘</fl>’; break;
case ’email’: $zoho_xml_data .= ‘<fl val=”Email”>’ . $value . ‘</fl>’; break;
case ‘phone’: $zoho_xml_data .= ‘<fl val=”Phone”>’ . $value . ‘</fl>’; break;
case ‘owner’: $zoho_xml_data .= ‘<fl val=”Lead Owner”>’ . $value . ‘</fl>’; break;
endswitch;
endforeach;

$zoho_xml_data .= ‘</row></Leads>’;
?>
[/code]

Notice we changedin the example to. The switch statement inside the foreach loop looks at each key of the data array, and if a match is found, adds it to the $zoho_xml_data variable.

You can add more cases to the switch statement for different Zoho fields as needed – even custom fields.

Define Zoho URL to send data to

We are going to change the sample URL from the API documentation to fit our needs with the CRM.

[code language=”php”]
<?php
$zoho_url = “https://crm.zoho.com/crm/private/xml/Leads/insertRecords?newFormat=1&amp;authtoken=” . $zoho_api_key . “&amp;scope=crmapi&amp;xmlData=” . urlencode($zoho_xml_data);
?>
[/code]

“crm/private/xml/Leads/insertRecords” will tell Zoho we are using a private section of the CRM, passing data in xml format to the leads module, and inserting a new record.

“authtoken” is the API key we defined earlier.

xmlData is our XML data (URL encoded)

Creating a cURL function to send the data

There are a lot of existing tutorials on cURL so I am not going to go over it here.

[code language=”php”]
<?php
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
?>
[/code]

Then we run the function, passing it the Zoho url with the URL encoded XML data.

[code language=”php”]
<?php
$response = cURLzoho($zoho_url);
?>
[/code]

If you run into trouble you can post $response to a log file to see what message the Zoho API gives you.

[code language=”php”]
<?php
file_put_contents(‘zohoResponse.log’, $response . “nn”, FILE_APPEND | LOCK_EX);
?>
[/code]

Test it out

Upload the script to your domain’s root. If you upload it elsewhere be sure to update the Wufoo WebHook URL to the appropriate place.

Visit your form on Wufoo or embed it on your site and test an entry.

If everything went well your log file should contain a message similiar to this one.

[code language=”xml”]<xml version=”1.0″ encoding=”UTF-8″ >
<response uri=”/crm/private/xml/Leads/insertRecords”><result><message>Record(s) added successfully</message><recorddetail><FL val=”Id”>491455000002394031</FL><FL val=”Created Time”>2012-11-20 15:24:57</FL><FL val=”Modified Time”>2012-11-20 15:24:57</FL><FL val=”Created By”><![CDATA[ZohoUserName]]></FL><FL val=”Modified By”><![CDATA[ZohoUserName]]></FL></recorddetail></result></response>[/code]

Note the ID number passed as a response. You can store the Lead ID and use it to update existing leads with the Zoho API.

Go take a look at Zoho and you can see the details of the newly created Lead.

Summary

This is a simple example but you should have the basics down and be able to expand this to fit your needs. For example you can have a sidebar “quick” contact form that captures Name, Phone and Email then redirect users to another form asking for more details and update the Lead if they choose to fill out the second form.

Here is a link to the complete sample script on github.

If you use the script please post a comment and let me know how it worked for you!

7 thoughts on “Using Wufoo WebHooks to add leads to Zoho CRM

    1. Hi Jeffrey – Glad it worked well for you. If you run into any trouble with some of the more advanced uses I hinted at like using multiple forms – a small form to create a lead and a more details form to update the lead – let me know. I would be happy to help you get it going.

  1. Hello Andrew,

    I am trying to create an online registration form and payment for our school program along with a teachers application, using Wufoo and integrating into Zoho CRM leads. Your summary looks beyond my capacity of accomplishment and I dont know what several things even mean!! However this does need to be done and I am the only person to do it.

    My question is: how do I add the additional field requirements for my registration forms and applications to all that you layed out on your simple integration example?

    Thank you for your help, Tina

    1. Hi Tina,
      I will do my best to point you in the right direction! You will need to do a few things. First off you will need to know the Zoho field names for the extra items you want to add. “First Name”, “Last Name”, and “Phone” are a few of the default ones. You will also need to know the Field names coming from the Wufoo form. See the “Capturing the form fields” section in the post for where to find these.

      Take a look at the complete script on Github. Lines 12 to 30 take the Wufoo Fields and store them in the $data array. You will need to mimic what is going on here with your additional fields. Lines 43 to 55 format the $data into XML that Zoho needs. Just mimic the “case” lines with your additional fields, updating the FL val=”” with the Zoho field name.

      If this is more then you think you can handle feel free to give us a call at 877-692-7250 and ask for Nate – he can get additional details about your needs and setup you up with a quote.

  2. Hello,

    My foundation runs a scholarship program and I am trying to import all scholarship information including 6 attachments that are required into Zoho from Wufoo. I have tried this multiple times but I believe it is beyond my expertise.

    How could I get a quote on you helping me out with this project? I have the document in the root, the wufoo application form made, zoho set up it, it is just editing the PhP that I can’t seem to figure out.

    Thank you for your help.

    Best,
    Jeremy

    1. Hi Jeremy,
      Unfortunately file attachments aren’t possible using this method. If you would like to discuss other options for Zoho integration feel free to give us a call.

Comments are closed.