$app->dsAdd( 'ContactAction', array( 'ContactId' => $referral, 'UserID' => 1, 'ActionType' => 'Other', 'ActionDescription' => 'Owner Assignment', 'CreationNotes' => "The referred user #{$referral} has been processed/tagged for appropriate ownership.", 'CompletionDate' => $api->infuDate(date('YmdTH:i:s', time())) ) );
How To Add Full Name To Infusionsoft As First and Last Name Fields
How To Apply/Remove a Tag
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.
How To Add A New Contact
This is the HTML for a sample form you can use for testing.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <title>Web Form Test</title> </head> <body> <!-- this tells the browser where and how to send the data from the form --> <form action='cb_add_contact.php' method='post' enctype="multipart/form-data"> <!-- the script puts this data into Infusionsoft --> First Name : <input type='text' name='FirstName'><br /> Last Name : <input type='text' name='LastName'><br /> Email : <input type='text' name='Email' ><br /> <input type='submit' value='Test'> </form> </body> </html>
This is the PHP for the script being called by the test form.
<?php echo "Hello World! <br/>"; // Connect to Infusionsoft require_once("isdk.php"); $app = new iSDK; if ($app->cfgCon("connectionName")) { // Current date in Infusionsoft-friendly format $currentDate = date_format(date_create(), 'YmdTH:i:s'); echo "You connected at $currentDate <br/>"; // Recipe begins here /* These are test values - make sure they are deleted or commented out when testing is complete */ //$fname = 'John'; //$lname = 'Kennedy'; //$email = 'jfk@whitehouse.gov'; // Check to see if the request method is POST or GET if ($_SERVER[REQUEST_METHOD] == 'POST') { if ($_POST['FirstName']) { $fname = $_POST['FirstName']; // These must match the name of the field in your form } else { $fname = ''; } if ($_POST['LastName']) { $lname = $_POST['LastName']; // including proper capitalization } else { $lname = ''; } if ($_POST['Email']) { $email = $_POST['Email']; } else { $email = ''; } } else { // We are going to assume it is a GET coming from an Action // This is a short hand for IF ELSE called a ternary operator $_GET['FirstName'] ? $fname = $_GET['FirstName'] : $fname = ''; $_GET['LastName'] ? $lname = $_GET['LastName'] : $lname = ''; $_GET['Email'] ? $email = $_GET['Email'] : $email = ''; // This does the same thing as the code in the IF // but notice how much cleaner and easier to read it is } // Update contact record using AddWithDupCheck method $data = array('FirstName' => $fname, // The key on the left must exact match table field names 'LastName' => $lname, // The value on the right can be anything as long as type matches field 'Email' => $email); // e.g you cannot put a string in date field $update = $app->addWithDupCheck($data, 'Email'); // This is the API call which checks for duplicates using Email and Name echo $update; // If successful, this will return the contactId of the contact added or updated } else { echo "Not Connected..."; } ?>