Skip to content

Instantly share code, notes, and snippets.

@ksnider
Last active December 31, 2015 19:39
Show Gist options
  • Select an option

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

Select an option

Save ksnider/8035198 to your computer and use it in GitHub Desktop.
<?php
// Connect to Infusionsoft
require_once("isdk.php");
$app = new iSDK;
$app->cfgCon("connectionName");
// Get Contact info from POST variable
//$contactId = $_POST['contactId'];
//$theDate = $_POST['theDate'];
// Create your own test contact and hard code here when testing. be sure to comment out
// the two $POST variables above. These are either-or.
$contactId = 18853;
$theDate = date_create("2013-12-19 16:30:00",timezone_open("America/New_York"));
$tagDate = date_format($theDate,'Ymd');
// Find the ID of the Event Registered tag for this date
$returnFields = array('Id');
$query = array('GroupCategoryId' => 33,
'GroupName' => $tagDate.'%');
$return = $app->dsQuery("ContactGroup",1,0,$query,$returnFields);
// This is a very handy piece of code. To print a varible, you use echo.
// This is how you print an array.
echo "<pre>";
print_r($return);
echo "</pre>";
// this doesn't do anything. In testing, I just wanted to see whether
// the tag existed or not and how that was represented. I left it here to make
// the point again, printing is your best friend. When in doubt ... print!
echo isset($return[0]['Id']);
// If a matching tag doesn't exist already ...
if(!isset($return[0]['Id'])) {
//Create the tag
$tag = array('GroupName' => $tagDate.' Extending IS',
'GroupCategoryId' => 33);
$theTag = $app->dsAdd("ContactGroup", $tag);
// If it does exist ...
} else {
// Grab that tag's ID so we can use it
$theTag = $return[0]['Id'];
}
// Whether we found it or created it, now we set it
echo $set = $app->grpAssign($contactId, $theTag);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment