Getting Started With The Infusionsoft API

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.

Useful Working Assumptions

  1. The Infusionsoft API is rate limited. While you’ll rarely run into this limit, it’s important to keep it in mind when writing your code. Pay particular attention when running tight loops. If you find that you’re trying to extract a lot of data at once from the API and it’s not working, there is a good chance you’re running into the rate limit. Unless you're constantly interacting with the API, you have 10,000 API calls to use. After that, you're limited to 2/second. In general, a sustained 2 requests a second is where you’ll want to be at to avoid getting rate limited. You can achieve this by adding sleep()’s to any tight loops. For a more detailed explanation regarding rate limiting, consult the general API documentation @ http://help.infusionsoft.com/api/rate_limiting.html

  2. While the API takes great care to make sure your data is stored safely and securely, simply using it won’t make your code anymore secure. You’ll need to adhere to the best practices for your language relating to security. Here are some great starting points for popular web languages. In addition, we’ll give you pointers where you have the opportunity to make your code more secure.

Configuring For The API

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)

To Find Your Private Key

1
2
3

Then add that key to your cfg file. If you find you don't have a key, enter an API Passphrase (A password that will generate your key. Don't use your general Infusionsoft Password) and hit save. This will generate a key for you.

$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.

Putting The API To Work

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.