Obviously it would be fantastic if Unbounce built proper integration with Batchbook, but this might help people in the interim.
November 29, 2011 05:21 pm
Carter Gilchrist
Unbounce
That's awesome Tim, thanks for sharing! Another option might be to try out http://onesaas.com/ - they are a bit of a Hub for SaaS companies like us. They have both Unbounce and Batchbook integrations, so I imagine you should be able to hook them up fairly easily. At any rate, this is a great interim solution!
November 29, 2011 05:43 pm
Tim Burgess
Yes Carter OneSaas is neat - I used to work with Corneliu and he's built a really great integration platform. Unfortunately we cobbled this together a few months before they released their Unbounce integration!
November 29, 2011 05:56 pm
Carter Gilchrist
Unbounce
Ahh bad timing! Well it's still a great solution for anyone who has access to some basic PHP hosting, be no means a waste of time :)
We're beginning development on our API here and are in discusion with OneSaas to better support their integration with us. Corneliu is indeed doing some very cool things over there.
November 29, 2011 06:17 pm
Dennis van der Heijden
Hi Tim, I see Batchbook removed your post. Can you repost it here, I am looking for that script as well?
Dennis
September 25, 2012 07:49 am
Tim Burgess
Hi Dennis,
Its below. Note that our script submits the application to batchbooks and also emails a confirmation with all the form fields to us. You may not need this extra step. Also it still (unfortunately) requires the manual step of approving each submission into batchbooks on the webform screen.
// This is a sample PHP script that demonstrates accepting a POST from the // Unbounce form submission webhook, and then sending an email notification. function stripslashes_deep($value) { $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
return $value; }
// First, grab the form data. Some things to note: // 1. PHP replaces the '.' in 'data.json' with an underscore. // 2. Your fields names will appear in the JSON data in all lower-case, // with underscores for spaces. // 3. We need to handle the case where PHP's 'magic_quotes_gpc' option // is enabled and automatically escapes quotation marks. if (get_magic_quotes_gpc()) { $unescaped_post_data = stripslashes_deep($_POST); } else { $unescaped_post_data = $_POST; } $form_data = json_decode($unescaped_post_data['data_json']);
//log submission date $submission_date = date("F j, Y g:i a"); $lead_source = 'unbounce';
//Email a notification of the entry to be made mail($to,$subject,$message_body,$headers);
?>
September 26, 2012 02:58 pm
Dennis van der Heijden
Hi Tim,
Excellent this worked well. Some info for other newbies like me.
This PHP file you save on your server, then go to Unbounce and in the page you connect it to the webhook per page. Paste the URL in the webhook and it will work. THen map the fields and your done.
You will be getting an email from the webhook with a batchbook URL and other contact details.
Smooth... great job Tim and thank you for sharing.
Comments
We use Batchbook and Unbounce. I posted the script we have used to integrate with the Unbounce Webhook here
http://support.batchbook.com/discussions/developers/166-unbounce-batchbooks-integration
Obviously it would be fantastic if Unbounce built proper integration with Batchbook, but this might help people in the interim.
That's awesome Tim, thanks for sharing! Another option might be to try out http://onesaas.com/ - they are a bit of a Hub for SaaS companies like us. They have both Unbounce and Batchbook integrations, so I imagine you should be able to hook them up fairly easily. At any rate, this is a great interim solution!
Yes Carter OneSaas is neat - I used to work with Corneliu and he's built a really great integration platform. Unfortunately we cobbled this together a few months before they released their Unbounce integration!
Ahh bad timing! Well it's still a great solution for anyone who has access to some basic PHP hosting, be no means a waste of time :)
We're beginning development on our API here and are in discusion with OneSaas to better support their integration with us. Corneliu is indeed doing some very cool things over there.
Hi Tim, I see Batchbook removed your post. Can you repost it here, I am looking for that script as well?
Dennis
Hi Dennis,
Its below. Note that our script submits the application to batchbooks and also emails a confirmation with all the form fields to us. You may not need this extra step. Also it still (unfortunately) requires the manual step of approving each submission into batchbooks on the webform screen.
<?php
// script to receive form response, email onwards, input into batchbooks
// http://webcache.googleusercontent.com/search?q=cache:hD-uRm1n0H8J:a...
$bb_account = 'accountname';
$bb_token = 'token';
// This is a sample PHP script that demonstrates accepting a POST from the
// Unbounce form submission webhook, and then sending an email notification.
function stripslashes_deep($value) {
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);
return $value;
}
// First, grab the form data. Some things to note:
// 1. PHP replaces the '.' in 'data.json' with an underscore.
// 2. Your fields names will appear in the JSON data in all lower-case,
// with underscores for spaces.
// 3. We need to handle the case where PHP's 'magic_quotes_gpc' option
// is enabled and automatically escapes quotation marks.
if (get_magic_quotes_gpc()) {
$unescaped_post_data = stripslashes_deep($_POST);
} else {
$unescaped_post_data = $_POST;
}
$form_data = json_decode($unescaped_post_data['data_json']);
//log submission date
$submission_date = date("F j, Y g:i a");
$lead_source = 'unbounce';
// Grab form data
$email_address = $form_data->email_address[0];
$company = $form_data->company[0];
$first_name = $form_data->first_name[0];
$last_name = $form_data->last_name[0];
$enquiry = $form_data->enquiry[0];
$job_title = $form_data->job_title[0];
$phone_number = $form_data->phone_number[0];
$age = $form_data->age[0];
$job_offer = $form_data->do_you_already_have_a_job_offer[0];
$citizenship = $form_data->citizenship[0];
$desired_location = $form_data->what_country_do_you_want_to_work_in[0];
$current_industry = $form_data->what_industry_do_you_work_in[0];
$current_location = $form_data->where_are_you_now[0];
$years_experience = $form_data->how_many_years_experience_do_you_have[0];
$education = $form_data->education[0];
$additional_information = $form_data->additional_information[0];
$services_of_interest = $form_data->services_of_interest[0];
$dependents = $form_data->do_you_have_dependents[0];
$start_date = $form_data->when_do_you_want_to_start_work[0];
$maintain_home = $form_data->do_you_maintain_a_house_in_your_home_country[0];
$contract_length = $form_data->how_long_is_the_role[0];
$time_current_location = $form_data->time_in_current_work_location[0];
$ip_address = $form_data->ip_address;
$utm_source = $form_data->utm_source[0];
$utm_medium = $form_data->utm_medium[0];
$utm_term = $form_data->utm_term[0];
$utm_content = $form_data->utm_content[0];
$utm_campaign = $form_data->utm_campaign[0];
$gclid = $form_data->gclid[0];
$landing_page = $form_data->landing_page[0];
$refer_url = $form_data->refer_url[0];
$ct_advert = $form_data->ct_advert[0];
$utm_visits = $form_data->utm_visits[0];
// Grab the remaining page data...
$page_id = $_POST['page_id'];
$page_url = $_POST['page_url'];
$variant = $_POST['variant'];
$page_name = $_POST['page_name'];
// Assemble the notes section of the new record...
$notes = <<<EOM
Personal Information \n
Email: $email_address \n
First Name: $first_name \n
Last Name: $last_name \n
Phone: $phone_number \n
Title : $job_title \n
Company: $company \n
Additional Information: $additional_information \n
\n
Enquiry: $enquiry \n
\n
Other form information \n
Lead Source : $lead_source \n
Services of Interest: $services_of_interest \n
What country they want to work in: $desired_location \n
Current location: $current_location \n
Citizenship: $citizenship \n
Current title: $job_title \n
Current industry: $current_industry \n
Years experience: $years_experience \n
Job Offer: $job_offer \n
Proposed start date: $start_date \n
Rate: $charge_rate \n
Age: $age \n
Dependents: $dependents \n
Education: $education \n
Submission Date: $submission_date \n
Webform : $page_name \n
Length of role: $contract_length \n
Time in current work location: $time_current_location \n
Maintain House in home country: $maintain_home \n
\n
Unbounce data \n
IP Address: $ip_address \n
Page ID: $page_id \n
URL: $page_url \n
Variant: $variant \n
\n
Google data \n
utm_source: $utm_source \n
utm_medium: $utm_medium \n
utm_term: $utm_term \n
utm_content: $utm_content \n
utm_campaign: $utm_campaign \n
ct_advert: $ct_advert \n
landing_page: $landing_page \n
utm_visits: $utm_visits \n
refer_url: $refer_url \n
Gclid: $gclid \n
EOM;
//create functions
function curlPost($data, $url, $token)
{
$post_data = returnPostParamStr($data);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST,true);
curl_setopt($curl, CURLOPT_POSTFIELDS,$post_data);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $token . ':X');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 15);
curl_setopt($curl, CURLOPT_VERBOSE, true);
$curl_response = curl_exec($curl);
curl_close($curl);
return $curl_response;;
}
function curlGet($url, $token)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, $token.':X');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$curl_result = curl_exec($ch);
curl_close ($ch);
// check results?
return $curl_result;
}
function curlPut($data, $url, $token)
{
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
$post_data = returnPostParamStr($data);
curl_setopt($curl, CURLOPT_POSTFIELDS,$post_data);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $token . ':X');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_TIMEOUT, 15);
curl_setopt($curl, CURLOPT_VERBOSE, true);
$curl_response = curl_exec($curl);
// test for http_code 200 good
$success = false;
$header_response = curl_getinfo($curl);
if($header_response[http_code] == "200")
{
$success = true;
}
curl_close($curl);
return $success;
}
function returnPostParamStr($val)
{
$string='';
if(is_array($val))
{
foreach($val as $k => $i)
{
$i = rawurlencode($i);
if($j==0){
$string.="$k=$i";
$j=1;
}
else if($k=='|S'){
$string.="$k=$i";
}
else{
$string.="&$k=$i";
}
}
}
return $string;
}
function extractCustomHeader($start,$end,$header)
{
$pattern = '#'. $start .'(.*?)'. $end .'#';
if (preg_match($pattern, $header, $result))
{
return $result[1];
}
else
{
return false;
}
}
//standard person array
$person = array('person[first_name]' => $first_name,
'person[last_name]' => $last_name,
'person[title]' => $job_title,
'person[notes]' => $notes);
$person_service_url = 'https://' . $bb_account . '.batchbook.com/service/people.xml';
echo "creating person...";
$person_response = curlPost($person, $person_service_url, $bb_token);
$status = extractCustomHeader('Status: ','[^0-9]*\n',$person_response);
// test for http_code 201 good, 422 - bad
if ($status <> '201')
{
echo 'oops';
return;
}
// Location: <a href="https://SUBDOMAIN.batchbook.com/service/people/149.xml">https://...>
$person_id = extractCustomHeader('Location: https://'.$bb_account.'.batchbook.com/service/people/','\.xml.*\n',$person_response);
// if ($person_id)
echo "success";
// Assemble the message body of the email using the $person_id
$message_body = <<<EOM
Personal Information \n
Email: $email_address \n
First Name: $first_name \n
Last Name: $last_name \n
Additional Information: $additional_information \n
Batchbooks URL: https://$bb_account.batchbook.com/contacts/show/$person_id \n
Phone: $phone_number \n
Title : $job_title \n
Company: $company \n
\n
Enquiry: $enquiry \n
\n
Other form information \n
Lead Source : $lead_source \n
Services of Interest: $services_of_interest \n
What country they want to work in: $desired_location \n
Current location: $current_location \n
Citizenship: $citizenship \n
Current title: $job_title \n
Current industry: $current_industry \n
Years experience: $years_experience \n
Job Offer: $job_offer \n
Proposed start date: $start_date \n
Rate: $charge_rate \n
Age: $age \n
Dependents: $dependents \n
Education: $education \n
Submission Date: $submission_date \n
Webform : $page_name \n
Length of role: $contract_length \n
Time in current work location: $time_current_location \n
Maintain House in home country: $maintain_home \n
\n
Unbounce Data \n
IP Address: $ip_address \n
Page ID: $page_id \n
URL: $page_url \n
Variant: $variant \n
\n
Google data \n
utm_source: $utm_source \n
utm_medium: $utm_medium \n
utm_term: $utm_term \n
utm_content: $utm_content \n
utm_campaign: $utm_campaign \n
ct_advert: $ct_advert \n
landing_page: $landing_page \n
utm_visits: $utm_visits \n
refer_url: $refer_url \n
Gclid: $gclid \n
EOM;
// add location
$location = array(
'location[label]' => 'work',
'location[email]' => $email_address,
'location[phone]' => $phone_number,
'location[country]' => $current_location
);
$location_service_url = 'https://'.$bb_account.'.batchbook.com/service/people/'.$person_id.'/locations.xml';
echo "adding location...";
$location_response = curlPost($location, $location_service_url, $bb_token);
$status = extractCustomHeader('Status: ','[^0-9]*\n',$location_response);
// test for http_code 201 good, 422 - bad
if ($status <> '201')
{
echo 'oops';
return;
}
//Location: <a href="https://SUBDOMAIN.batchbook.com/service/locations/150.xml">https...>
echo "success";
// add tag
$tag = array(
'tag' => 'leads',
);
$add_tag_person_service_url = 'https://'.$bb_account.'.batchbook.com/service/people/'.$person_id.'/add_tag.xml';
echo "adding tag...";
if (!curlPut($tag, $add_tag_person_service_url, $bb_token))
{
echo 'oops';
return;
}
echo "success";
// create new communication
$communication = array(
'communication[subject]' => 'Unbounce Lead: ' . $page_name,
'communication[body]' => $message_body,
'communication[date]' => date("F j, Y, g:i a"),
'communication[ctype]' => 'Email'
);
$communication_service_url = 'https://' . $bb_account . '.batchbook.com/service/communications.xml';
echo "creating communication...";
$comm_response = curlPost($communication, $communication_service_url, $bb_token);
$status = extractCustomHeader('Status: ','[^0-9]*\n',$comm_response);
// test for http_code 201 good, 422 - bad
if ($status <> '201')
{
echo 'oops';
return;
}
//Location: <a href="https://SUBDOMAIN.batchbook.com/service/communications/151.xml">...>
$comm_id = extractCustomHeader('Location: https://'.$bb_account.'.batchbook.com/service/communications/','\.xml.*\n',$comm_response);
// if ($comm_id)
echo "success";
// add participant to communication
// Role (one of: 'to', 'from', or 'cc')
$communication = array(
'contact_id' => $person_id,
'role' => 'from'
);
$role_communication_service_url = 'https://'.$bb_account.'.batchbook.com/service/communications/'.$comm_id.'/add_participant.xml';
echo "adding _to_ role to communication...";
if (!curlPut($communication, $role_communication_service_url, $bb_token))
{
echo 'oops';
return;
}
echo "success";
//send email to confirm all has happened
//Assemble Message headers
$to = "email@yourcompany.com";
$subject = "$page_name : Unbounce Submission";
$headers = "From: $first_name $last_name <$email_address>";
//Email a notification of the entry to be made
mail($to,$subject,$message_body,$headers);
?>
Hi Tim,
Excellent this worked well. Some info for other newbies like me.
This PHP file you save on your server, then go to Unbounce and in the page you connect it to the webhook per page. Paste the URL in the webhook and it will work. THen map the fields and your done.
You will be getting an email from the webhook with a batchbook URL and other contact details.
Smooth... great job Tim and thank you for sharing.
Dennis
My opinion is that http://www.c9gold.com like you, it’s very http://www.buyc9.com funny, but I don’t know http://www.c9money.com how it could be judged by him.