Tip:
Highlight text to annotate it
X
Good morning, this is Jacob Allred with Novak Solutions. Today we're going to be talking
about the Infusionsoft API and the Novak Solutions SDK. The API is an interface that allows you
to connect third party applications directly to your Infusionsoft app. For example, you
can have your WordPress blog talk to Infusionsoft to add contacts or to pull contact information
out. Infusionsoft provides a free SDK that allows you to use the API through PHP. Like
I said it's free, it is also powerful, and has a fair amount of documentation, but it
also has a few issues that developers sometimes encounter such as blank responses from the
API or error messages. And it has a bit of a learning curve that can make it difficult
to get started with. At Novak Solutions we've developed a new and improved SDK. It's also
completely free. It's also powerful. And we're going to show you today how to use it to get
contacts into Infusionsoft. Before we get started though I'd like to go over some of
the benefits of the SDK. First of all it doesn't have any dependencies other than PHP and cURL,
which most servers already have. It has code completion for IDEs like Eclipse and PhpStorm.
It automatically retries API calls if they fail and it is safe to retry it such as a
"delete". So if you're trying to delete a contact and you get an error message back,
our SDK will automatically try that delete again to make sure it went through. The SDK
can automatically handle XML-RPC, which is sort of the language the API talks. Instead
of having to form your own XML requests or decode them, the SDK will do that for you
automatically. It also works around a few of the bugs the Infusionsoft API has, especially
when it comes to international character sets. Saving records is easier in the Novak Solutions
SDK. It will automatically pick whether to do an "insert" or an "update" based on whether
you're working with a new or existing record, so you don't have to figure out which method
to use on your own. We've also made the SDK future safe. If Infusionsoft decides to drop
fields in the future like they have in the past, our SDK is just going to keep on working.
You don't have to worry about. So now that we've gone over some of the benefits, I want
to show you an example of how to get a contact from code into Infusionsoft. To start you'll
need the SDK. We keep the latest version available at GitHub. That's at joeynovak/infusionsoft-php-sdk.
This is the same service that a lot of major companies use to provide free code to the
public. It makes it easy for us to collaborate with people on the internet. For example,
if you want to add your own feature to the SDK, you can do that and then you request
us to merge it into our code so the whole community can benefit from your work. So to
get started we're going to grab the URL in the corner. This URL will let us copy the
entire code onto our own computer. So I'm going to go in here and "git clone" and then
the URL to the repository. It takes just a moment for it to copy that to your computer.
And it's already done. So we can come over here and see here's the SDK. There's a lot
of different files related with it. I like to use NetBeans. I'm going to go ahead and
pull up the SDK files in NetBeans, which is just an IDE. It's just a tool to make it easier
to develop. So I like said, there's a lot of files related with the SDK. Luckily you
don't have to worry about almost any of them. You include one file and it automatically
pulls in the other files as needed in a very efficient way, so you don't have to worry
about too much load on your server or using too much memory. So we're going to go ahead
and create a new files. Let's call it "new-contact". And in this file we're going to use the SDK
to insert a contact into our Infusionsoft app. So before we get started here we need
to configure the SDK to be able to talk to our Infusionsoft app. To do that, we're going
to find the config file, which is down here. We're going to copy the sample and put the
sample into config.php. So we just copied the contents of config.sample.php and we're
copied it into config.php. So there are two parts here we need to configure. The first
is your Infusionsoft host. The Infusionsoft host is your full URL for your Infusionsoft
app. So I have a sandbox app up here. The URL is az169.infusionsoft.com. I'm going to
copy that over here. You also need your API key. To get your API key, go back to your
app. You're going to go to Admin, Settings. Click on Application on the left. Scroll down
to the bottom. The API key is your Encrypted Key. This is a very secret key. You don't
want to give this to people that you don't trust. Anyone that has your Encrypted Key,
or your API key, has access to everything in your Infusionsoft app except for credit
card numbers. They can take all that information out. They can delete all that information.
And if you're not running backups using a tool like our Infusionsoft backup tool, then
you're not going to have any way to get that data back. If you don't see a key here, you'll
need to enter a passphrase. The API passphrase can be anything you want. It doesn't really
matter, it's just used to generate the key. So I'm going to copy this key. I'm going to
copy it into here. And save. And there we go. That's all it takes to configure it. I
have my host name. I have my API key. I can close this file. So now we have a blank file
to get started with. The first step is to include the SDK into our script here. So to
do that we're going to "require" Infusionsoft/infusionsoft.php. So this includes the SDK. That one line of
code makes all of the SDK available. It automatically pulls in all of the files that are needed.
If you want to use contacts, it will automatically pull in the contacts PHP file. If you are
looking to mess with tickets, it will pull in the tickets PHP file. Everything is automatic.
So for our example we want to add a contact. So we're going to create a new contact object,
which is Infusionsoft_Contact. Here's the code completion I was talking about. So what
this does is it creates a new contact object that we can now add our information to and
then save back to Infusionsoft. You can do something similar with any of the other tables
that are in Infusionsoft, such as products or leads or invoices. All of these different
things you could do just as easily by doing Infusionsoft_ the table you want to use. So
we're going to do a contact and then it's just very easy, it's just added the information
to the object and then saving it back. Infusionsoft provides a documentation page that lets you
know all the fields that are available. And you can find a link to that underneath the
video. So for our example we want to add first name. I'll call it Jacob. We'll want to add
a last name. Allred. We can add an email address. Capitalized. We can add other information
to. I can add in my address, I can add in a lead source, all that information you see
in Infusionsoft can be added in here. And then to get that into Infusionsoft we're going
to call save. With our SDK like I mentioned before you don't have to know whether you
are creating a new contact or updating an existing one. It automatically handles that
for you to call the correct method. So save tells it to go ahead and put that information
into Infusionsoft. We're going to save our file. And then we can go back to our command
prompt. I'm going to use PHP to run the file. So php, we called it new-contact.php. The
codes going to run. We can now go back to our application here. Go to our contact list.
And we can see here's the contact we just created. Pretty easy. Another great thing,
you can also use it for custom fields. It takes a little bit more effort to do a custom
field. Let me show you how to do that. So for my example I have a custom field called
favorite food. We're going to go ahead and figure out what that field's name is in the
Infusionsoft database. We do that by going to Admin, Settings. We go to our custom fields
for contact. And it's going to have this link "View the field database names for the API".
If you click that it's going to pop up a window that shows all your custom fields, what kind
of field it is, and what the database name is. I only have one because this is just a
sandbox app. So the database name is FavoriteFood with no spaces. When you're using the API
you need to add an underscore in the front so we're going to have _FavoriteFood. So if
we go back to our code here, first we need to tell the SDK that the custom field exists.
So we're going to say custom equals array. And this is just going to be an array of our
custom arrays. So favorite food. If I had another custom field called like hated foods,
you could do that. You could add more than one field at a time. So we're going to add
favorite food, and then we have to use our contact object to add custom fields and we're
going to pass in this array we just created. If you're only doing a single field you could
just do it add custom field, favorite foods. That might be a little bit easier if you're
only doing a single field. I prefer to do the add custom fields because then you can
easily go back and add another field later. Alright, so we've added the custom field.
The SDK now knows it exists. Let's do a new contact. Let's call it John Doe. john@novaksolutions.com.
And we're going to add our favorite food. He likes pizza. So it's the same code as before
we've just added the custom field so that the SDK knows it exists. We've added favorite
food to the object. We're still doing save. Let's save this file. Let's run php new-contact
again. And this is just running this code. If you have this on a web server you could
call it through a URL on your web server. You could call it from a cron job if you're
having something run on a schedule. There's a lot of different ways to call this file
once you've created it. We're going to run that file. It takes just a moment to talk
to the API for us. We go back to our app. Go to contacts. We now have a second contact,
John Doe. We can go over to our custom fields. We can see favorite food is pizza. So that's
just a very basic example of how to get data inside Infusionsoft from an external system.You
can do a lot of powerful things with it. You can add tags automatically based on an action
in another system. We use the API in our WordPress upsell plugin to make it very easy to make
it so a customer can buy an additional product after they just finished purchasing one. We
use it like I said in all of our applications we do for our customers. So I hope you enjoyed
this screencast. I hope it helped you get a little bit of a taste for what the API can
do for you and helped you get a little bit of insight in how to get started. If you have
any questions, feel free to post a comment or email me directly: jacob@novaksolutions.com.
I'm happy to help as much as I can. And I hope you have a great day! Thanks!