Skip to content

Instantly share code, notes, and snippets.

@ksnider
Created December 5, 2013 18:45
Show Gist options
  • Select an option

  • Save ksnider/7810941 to your computer and use it in GitHub Desktop.

Select an option

Save ksnider/7810941 to your computer and use it in GitHub Desktop.
This script adds up the total of all orders for an Infusionsoft contact and puts it in a custom field
<?php
// Connect to the Infusionsoft API
require("isdk.php");
$app = new iSDK;
$app->cfgCon("connectionName");
// Get the contact ID
$contactID = 19309;
// $contactId = $_POST['Id'];
// Query the Invoice table for all invoices
$returnFields = array('DateCreated','InvoiceTotal');
$query = array('ContactId' => $contactID);
$invoices = $app->dsQuery("Invoice",10,0,$query,$returnFields);
echo "<pre>";
print_r($invoices);
echo "</pre>";
$totalPurchases = 0;
// Loop through the invoices and add the total to the variable $totalPurchases
foreach ($invoices as $value) {
$totalPurchases = $totalPurchases + $value['InvoiceTotal'];
// Shorthand but harder to read
// $totalPurchases += $totalPurchases;
}
echo "$".$totalPurchases . "<br/>";
// Update contact record with Total Purchases
$data = array('_Purchases' => $totalPurchases);
$update = $app->dsUpdate("Contact", $contactID, $data);
echo $update;
/* **************
PROJECT _ Once you have run this for all of your customers, modify to increment _Purchases by last purchase using billing automation or campaign trigger
EXTEND - When total purchases = $X, apply a tag to kick off an email with a coupon
******************* */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment