Skip to content

Instantly share code, notes, and snippets.

@joshuaziering
Last active December 18, 2015 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshuaziering/5719175 to your computer and use it in GitHub Desktop.
Save joshuaziering/5719175 to your computer and use it in GitHub Desktop.
Webhook To Bring Email Addresses From Shopify To Infusionsoft
<?php
/**
* Webhook Handler For Shopify To Infusionsoft
*
* @author Joshua Ziering <josh@vuurr.com>
*/
// Include and instantiate Infusionsoft Libraries
include('isdk.php');
$ifsapp = new iSDK;
// Here's a sample set of data like the Shopify API posts to this application that you can use for testing.
/*
$customer_information = '{
"customer": {
"first_name": "Steve",
"last_name": "Lastnameson",
"email": "steve.lastnameson1@lastnamesonco.com",
"verified_email": true,
"addresses": [
{
"address1": "123 Oak St",
"city": "Ottawa",
"country": "CA",
"first_name": "Mother",
"last_name": "Lastnameson",
"phone": "555-1212",
"province": "ON",
"zip": "123 ABC"
}
]
}
}';
*/
//$raw = file_get_contents('php://input');
$customer_information = json_decode(file_get_contents('php://input'));
//file_put_contents("jsonoutput.txt", $raw);
if (!$ifsapp->cfgCon("YourEndpointName","YourAPIKey1234567890")) {
echo "There was a problem connecting to Infusionsoft.";
}
// If they've input their email...
if ( ! empty($customer_information->customer->email))
{
global $ifsapp;
// First check to see if this email exists in our Infusionsoft database.
$contact = array(
'Email' => $customer_information->customer->email,
'FirstName' => $customer_information->customer->first_name,
'LastName' => $customer_information->customer->last_name
);
// Check for existing contact
$returnFields = array('Id');
$duplicates = $ifsapp->findByEmail($contact['Email'], $returnFields);
if (!$duplicates)
{
// Add a new contact
//echo "Adding new email.";
$newCon = $ifsapp->addCon($contact);
}
}
header('HTTP/1.0 200 OK');
exit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment