// Add connection info here <pre>$sendTo = array(12,16,22); $templateID = 3380 $app->sendTemplate($sendTo,$templateID);
How To Change the Opportunity Stage
</p> <p><?php </p> <p>echo "Hello World! <br/><br/>"; </p> <p>// Connect to Infusionsoft</p> <p>require_once("isdk.php");<br /> $app = new iSDK;<br /> if ($app->cfgCon("sandbox")) { // Make sure this matches your connection name in conn.cfg</p> <p>// Recipe starts here</p> <p> // Current date in Infusionsoft-friendly format</p> <p> $currentDate = date_format(date_create(), 'YmdTH:i:s');<br /> echo "You connected at $currentDate <br/><br/>";</p> <p> $contactId = 129; // Dritte Dawg<br /> $newStageId = 24; // Change this StageID to whatever you want it to change it to</p> <p> // API Call -> Query the lead table to find the opportunities for this contact</p> <p> $qryFields = array('Id', 'ContactID', 'StageID');<br /> $query = array('ContactID' => $contactId);<br /> $myOpp = $app->dsQuery("Lead",5,0,$query,$qryFields);</p> <p> //Remove these three lines when done testing<br /> echo "<pre>";<br /> print_r($myOpp);<br /> echo "</pre>";</p> <p>// Update the opportunity with the new stage</p> <p> $update= array('StageID' => $newStageId);<br /> $oppID = $myOpp[0]['Id']; // This line assumes there is only one opp fpr this contact<br /> $opp = $app->dsUpdate("Lead", $oppID, $update);</p> <p> // Remove this line when done testing<br /> echo "<br/>Updated Opp ID# ".$opp." <br/>";</p> <p>} else {<br /> echo "Not Connected...";<br /> } </p> <p>
How To Change the Owner ID
<?php // Connect to the Infusionsoft API require("isdk.php"); $app = new iSDK; $app->cfgCon("sandbox"); // Notice the names in red match up to the names sent in the http post snippet $contactId = $_POST['contactId']; $repId = $_POST['repId']; // API call -> update contact record for $ContactId with the information in $rep $rep = array('OwnerID' => $repId); $owner = $app->dsUpdate("Contact", $contactId, $rep);
How To Set A Custom Field To A Date
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 get a judo grip on the code and its nuances and let you cater the code to your needs.
<?php //Connects to the Infusionsoft API. This is a standard way to start any script that uses the Infusionsoft API. No tweaks necessary here! require("isdk.php"); $app = new iSDK; $app->cfgCon("connectionName"); //The variable (dateFieldName) stores the name of the custom Infusionsoft field where the date will be posted (NameOfYourDateField in this case). // Custom fields in Infusionsoft always have an underscore before their name when being referenced by a script. $dateFieldName = '_NameOfYourDateField'; //Get post data for Contact ID. $contactId = $_POST['Id']; //Stores today's date in YearMonthDate format. $currentDate = date("YmdTH:i:s"); //Grabs the data from Infusionsoft for your custom field. $returnFields = array($dateFieldName); //dsLoad is an Infusionsoft API method that grabs data from the specified field in Infusionsoft. $contacts = $app->dsLoad("Contact", $contactId, $returnFields); //If NameOfYourDateField is currently empty/unset, then set it to today's date. If it's already set, add one year to the date if (isset ($contacts['_NameOfYourDateField']) == FALSE) { $conDat = array($dateFieldName => $currentDate); } else { $classOf = strtotime($contacts['_NameOfYourDateField']); $yrPlusOne = date("YmdTH:i:s", strtotime('+1 year', $classOf)); $conDat = array($dateFieldName => $yrPlusOne); } //Another API method that updates a given contact with the data in the second variable passed. $conID = $app->updateCon($contactId, $conDat); ?>
3) Now that you’ve got the code in your text editor, it’s time to edit it to suit your needs/wants/whimsies. 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:
$dateFieldName = '_NameOfYourDateField';
As the comment says, dateFieldName is a variable that will represent the custom field where you want to put the date in Infusionsoft. You need to change ‘_NameOfYourDateField’ to ‘_WhateverYourCustomFieldIsActuallyCalled’. For instance, if you wanted to put the date in a custom Infusionsoft field called MyCustomDate, you would put ‘_MyCustomDate’. You also need to change this anywhere else the code references ‘_NameOfYourDateField’, so in your text editor use the Find-and-Replace function to change all instances of ‘_NameOfYourDateField’ to ‘_MyCustomDate’ or whatever you named your field.
4) Jump down to the line
$currentDate = date("YmdTH:i:s");
Right now, this bit of PHP will store the current date in a variable aptly named currentDate in the format YYYYMMDD followed by the time-zone abbreviation followed by the time in 24-hour/military time format. So if it was 3:19 PM on September 20th, 2013 in Eastern Standard Time, the script would format the date as 20130920EST15:19:00. This is handled in the code by the part in quotes that looks like a cat ran across the keyboard (“YmdTH:i:s”) and you can change it around however you want. This is how it presently breaks down:
Y – The 4-digit year
m – The 2-digit month with leading zeroes (
d – The 2-digit day with leading zeroes.
T – Time-zone abbreviation
H – The hour using a 24-hour clock
i – Minutes
s – seconds
You could re-arrange it to (“m d Y H:i:s T”) and the script would then format the date as 09 20 2013 15:19:00 EST. You can also change how the date appears by switching the letters you use. For instance, changing the ‘m’ to ‘F’ would make the month in the date appear as “September” instead of “09.” For a full list of all possible formatting options, refer to the PHP manual here : http://php.net/manual/en/function.date.php.
5) The last line you might want to tweak is:
$yrPlusOne = date("YmdTH:i:s", strtotime('+1 year', $classOf));
Currently, this script will add one year to the contact’s custom date field every time you run this script. So if you initially set the contact’s date to 09/20/2013 (formatted however you chose, obviously), the next time you run the script that date will be updated to 09/20/2014. You can change ‘+1 year’ to ‘+1 month’ or ‘+1 day’ depending on what increment you want. Go ahead, try it! It’s like magic. Internet magic.
And that’s it! Congratulations, you have a custom date in a custom field that goes up by a custom increment every time you run this script. It’s so custom that “custom” probably doesn’t sound like a real word to you anymore!
How To Capitalize First Name
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 get a judo grip on the code and its nuances and let you cater the code to your needs.
<?php echo "Hello World! <br/><br/>"; // Connect to Infusionsoft require_once("isdk.php"); $app = new iSDK; if ($app->cfgCon("sandbox")) { // Current date in Infusionsoft-friendly format $currentDate = date_format(date_create(), 'YmdTH:i:s'); echo "You connected at $currentDate <br/><br/>"; // Recipe starts here // Assign POST variables using ternary operator instead of IF statement // If your POST is being sent from somewhere other than Infusionsoft, // you may need to modify the name in $_POST[] to match form field name or key if ($_POST['Id']) { $conID = $_POST['Id']; } else { $conID = ($_POST['contactId']) ? $_POST['contactId'] : ''; } $fname = ($_POST['FirstName']) ? $_POST['FirstName'] : ''; // Make the value all lower case and then capitalize first letter $capname = ucwords(strtolower($fname)); // Write the result back to First Name field in Infusionsoft $conDat = array('FirstName' => $capname); $conID = $app->updateCon($conID, $conDat); } else { echo "Not Connected..."; }
3) Now that you’ve got the code in your text editor, it’s time to edit it to suit your needs/wants/whimsies. 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 these lines:
if ($_POST['Id']) { $conID = $_POST['Id']; } else { $conID = ($_POST['contactId']) ? $_POST['contactId'] : ''; }
These lines are using the Ternary Operator as a shorthand for a traditional nested If/Else Statement to get the Contact Id, if it exists, from the $_POST variable. Because we aren’t sure where the $_POST variable is coming from, we need to allow for all cases. If it’s coming from an Infusionsoft Action Set, “Id” is going to get assigned to $conID. If it’s coming from the Campaign Builder, “contactId” is going to get assigned to $conID. And if it’s coming from an external source like a Gravity Form on your website, there may be no Contact Id at all, in which case we need to tell $conID this field should be empty.
The only reason you may need to change this code is if you decide to change the default (“contactId”) in Campaign Builder to something else. In that case, you’ll need to replace “contactId” with your new variable name. Otherwise, you’re good to go.
4) You probably will need to change line 30 if you’re using an external form or if you change the Infusionsoft default (“FirstName”) in Campaign Builder. Remember, variables are case sensitive, so “firstname” is NOT the same as “FirstName”. Yours may be “First”, “Name” or any variation. Make sure your variable name matches here.
$fname = ($_POST['FirstName']) ? $_POST['FirstName'] : '';
In line 38 there’s another instance of the $_POST variable that you may need to change.
$conDat = array('FirstName' => $capname);
Other than these changes, the rest of the code should work right out of the box. Remember, your clients are probably just as sloppy getting their last names in their contact records too, so have fun getting those looking good with a little alteration to this code!