The Infusionsoft API is an incredibly powerful tool to enable you to interact with all the features you enjoy on the web interface, albeit programmatically. This getting started guide uses the PHP SDK in the examples. This guide also assumes a basic level of programming knowledge, but makes special consideration for beginners who may not have as much experience.
In order for you to gain familiarity with the API, we’ll be building some basic form interaction.
Python: http://www.pythonsecurity.org/
C#: http://msdn.microsoft.com/en-us/library/ms173195(v=vs.80).aspx
The latest version of the PHP SDK is available here: https://github.com/infusionsoft/PHP-iSDK
When you’re calling the API, you’ll need to call it with your subdomain at Infusionsoft. This is the same URL that you login at from the web interface.
https://YOURAPPHERE.infusionsoft.com/
Every single call to the Infusionsoft API is encrypted with HTTPS. Your calls will fail if you're not able to support HTTPS.
You’ll need to include your private key with every call to authenticate yourself to the application. This is how Infusionsoft knows who is asking for your data.
We’ll be starting every interaction the same way, by authenticating ourselves to the server. The good news is that when you initialize, the SDK will handle all of this for you.
When looking at code examples, keep an eye out for explanatory comments.
Here’s the conn.cfg.php with the credentials available in your Infusionsoft account under Admin-> Settings -> Application > API (At the bottom of the page)
$connInfo = array('connectionName:YourAppName:i:XXXXXPRIVATE_KEYXXXXX:This is the connection for YourAppName.infusionsoft.com');
The first part of the each configuration line is the "name" of that connection, followed by parameters to set the application name, API key, API type, and comments.
Once you’re configured and connected, you can start making calls to the API. The Infusionsoft iSDK does most of the leg work for you. After you’ve created the object, it will remember your connection details and supply them on any subsequent call.
It’s not compulsory to do $app->cfgCon before your first call, but it’s recommended because it will let you now if you have a problem with your connection right away, rather than before you get into your program’s logic.
As an example exercise we’ll be writing code to read in data from a form, query the Infusionsoft API, and output the information returned.
Your program logic should be encapsulated in a successful test call to the API. If you're taking an object oriented approach, you'd want to place this code in your constructor.
<?php
require("isdk.php");
$app = new iSDK;
if($app->cfgCon("connectionName"))
{
//This is the name referenced in conn.cfg.php
echo "app connected!<br/>";
}
else
{
echo "connection failed!<br/>";
}
For the sake of brevity we’ll avoid doing sanity checks, but you should be checking to make sure that your email is in the correct format and that the name is in the correct format. Also test to make sure they’ aren’t blank!
<?php
//First, let’s read in the data from our form and make sure it’s sane.
$email = $_POST[‘email’];
$first_name = $_POST[‘first’];
$last_name = $_POST[‘last’];
It's highly encouraged that you process your variables to make sure that they're safe to put in your database. In addition, it's important to note the the Infusionsoft API is NOT case sensitive. So Test@Test.com will match test@test.com.
When working with methods that return items, the SDK requires that you send array to specify which items you want to return. If you send an empty array, you'll get back the most rudimentary form of the data you asked for. For example, with the Contact service, you'll just get the Contact ID.
$returnFields = array('Id', 'FirstName', 'LastName'); $contacts = $app->findByEmail("johndoe@gmail.com",$returnFields);
When your data is returned, it will be returned as an array of associative arrays.
print_r($contacts) Array ( [0] => Array ( [FirstName] => John [Id] => 3 [LastName] => Doe ) )
When you run into questions about what a particular call is returning, it's often very useful to use the print_r function to help understand what the calls are returning, and how you can reference them. When you put it all together you get:
require("isdk.php"); $app = new iSDK; if($app->cfgCon("connectionName")) { //This is the name referenced in conn.cfg.php echo "app connected!"; } else { echo "connection failed!"; die(); } $returnFields = array('Id', 'FirstName', 'LastName'); $emails = $app->findByEmail("jondoe@gmail.com",$returnFields); if(sizeof($emails) == 0) { echo "Found no one by that name"; }
The API documentation is your gateway to finding the answers you need. It's a living document that's available on GitHub in case you find yourself wanting to make contributions. There, you can find examples for all the methods, as well as examples of using the PHP SDK. You can find all the documentation here.