1) Open your favorite text editing program
2) Copy and paste the following PHP code into the blank text editor file:
NOTE: Lines beginning with “//” denote comments explaining what the subsequent chunk of code does. They also sometimes point out things you can change or customize in the code. Reading through them will help you conquer the code and its nuances and let you modify the code to suit your needs.
<?php // Connect to Infusionsoft require_once("isdk.php"); $app = new iSDK; if ($app->cfgCon("sandbox")) { // change this to match your connection name in conn.cfg // Current date in Infusionsoft-friendly format $currentDate = date_format(date_create(), 'YmdTH:i:s'); echo "You connected at $currentDate <br/><br/>"; // Recipe begins here $contactId = 104; // This is the contact you want to add the tag to - modify as needed $srvcGood = 106; // This is the tag ID, which you find in Infusionsoft CR< Settings -> Tags $srvcBad = 108; // Remove a tag from Contact using grpRemove // NOTE: You can only add or remove one tag at a time $result1 = $app->grpRemove($contactId, $srvcGood); $result2 = $app->grpRemove($contactId, $srvcBad); echo "<pre>"; var_dump($result1); echo "</pre>"; // Add a tag to Contact using grpAssign $result = $app->grpAssign($contactId, $srvcGood); // This is the API call that adds the tag echo "<pre>"; var_dump($result); echo "</pre>"; // Example use case - you will be applying a tag at the end of a script to kick off // a campaign in campaign builder. Because that tag may already exist on that contact ID, // it is a good idea to remove it at the beginning of your script and then reapply. } else { echo "Not Connected..."; }
3) Now that you’ve got the code in your text editor, it’s time to season to taste. Most of the script should work just fine as-is, but it does need a few customizations here and there. First, let’s look at this line:
$contactId = 104;
This line of code is what we call “hard coded” with the Contact Id. In other words, the Contact Id of 104 is specifically programmed into the program. Please understand that Contact Id 104 belongs to a contact in MY Infusionsoft application. You will need to find a specific contact in YOUR application, make note of that Id, and replace my 104 with your particular contact Id number. The Contact Id number can be found by going to Infusionsoft/CRM/Contacts. You’ll see the Id right under the contact’s name.
The same “hard coded” concept holds true for the next 2 lines. You will need to find two tags in YOUR application to replace my 106 and 108. You can find your Tag Id’s by going to Infusionsoft/CRM/Settings/Tags.
$srvcGood = 106;
$srvcBad = 108;
You may also want to change the variables “$srvcGood” and “$srvcBad” to something that makes more sense to you for your chosen tags. Just be sure to keep the $ before each, and to make your changes both when we first declare the variables here:
$srvcGood = 106;
$srvcBad = 108;
as well as when we call our grpRemove and grpAssign methods on these lines:
$result1 = $app->grpRemove($contactId, $srvcGood);
$result2 = $app->grpRemove($contactId, $srvcBad);
$result = $app->grpAssign($contactId, $srvcGood);
That’s about it. You can now confidently apply and remove tags from your contacts right from the API.