Languages: PHP | Difficulty: Easy
Introduction
The Keap PHP SDK provides a simple way for you to get started with integrating usage of the Keap REST API into your application. Features include:
- Loading & installation of all files and dependencies via Composer
- Support for custom HTTP clients via Guzzle
- Simple, normalized interface for accessing each function of the API
This tutorial will demonstrate how to install, set up, and use the Keap PHP SDK to start making requests to the Keap REST Core Service.
Next: Install the SDK
Install the SDK
We highly recommend using Composer to manage installation of the Keap PHP SDK. To learn more about Composer, check out the Composer getting started guide.
Requirements: PHP 8.1 and later.
To install the SDK via Composer, add the following to your composer.json file:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/infusionsoft/keap-sdk.git"
}
],
"require": {
"keap/keap-sdk": "*@dev"
}
}
Then run:
composer install
You're all set! If you're not using a PHP framework that is already autoloading your Composer vendor directory, you'll also want to include the following at the start of your PHP file:
require_once '/path/to/core-v2-client/vendor/autoload.php';
For more information and support, visit developer.keap.com/get-support.
Next: Create an Infusionsoft API Object
Create an Infusionsoft API Object
For the next step you're going to need your Keap API credentials. Don't have them? Visit the Keap Developer portal to get started.
Let's create a new Keap API instance. First, include the autoloader and set up your HTTP client:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
$apiInstance = new KeapCoreV2ApiAffiliateApi(
// If you want to use a custom HTTP client, pass your client
// which implements `GuzzleHttpClientInterface`.
// This is optional, `GuzzleHttpClient` will be used as default.
new GuzzleHttpClient()
);
The SDK uses Guzzle as its default HTTP client. You can pass your own custom client that implements GuzzleHttpClientInterface if you need to customize request behavior (e.g., proxies, timeouts, or middleware).
Now you can start making API calls. Here's a quick example:
$request = new KeapCoreV2ModelCreateAffiliateRequest();
try {
$result = $apiInstance->addAffiliate($request);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling AffiliateApi->addAffiliate: ',
$e->getMessage(), PHP_EOL;
}
Next: Check for an access token
Check for an access token
In order to make requests to the API, you'll need an access token to authenticate on behalf of a Keap customer. For detailed instructions on how to obtain and manage your access token using OAuth 2.0, check out the OAuth authentication guide.
I’m a little confused here… why is API access mediated by users needing to click any kind of authorization? Isn’t that the point of providing a secret key? I use the API to put Infusionsoft data in front of my customers who have no idea what Infusionsoft is and are not the Infusionsoft user. How does this work??
Hi Greg,
OAuth2 is now the standard way of giving API access. From the sounds of it, you are the Infusionsoft user. This means you have to authorize the access one-time. Your customers will never know about Infusionsoft with this.
We have another tutorial that explains better how to do this. I recommend you go check it out. https://developer.infusionsoft.com/tutorials/making-oauth-requests-without-user-authorization/
Thank you for the reply and the link – you’re 100% right. Unfortunately, the tutorial you linked to (should I have commented on that page instead?) doesn’t actually have a single line of example code.
We use the PHP iSDK right now but I’d like to migrate to the PHP SDK (should I?). Unfortunately, I’m having a problem finding any detailed tutorial information on how to setup the authentication and token refreshes. Can you point me in the direction of anything suitable?
Thanks a ton.
greg
Check out some of the other tutorials here: https://developer.infusionsoft.com/tutorials/
There are two that can help you with the PHP implementation, and the readme on the repo https://github.com/infusionsoft/infusionsoft-php also has a nice simple tutorial on retrieving and refreshing an access token.
But isnt that just plain stupid? Why is oAuth2 the ONLY way of authenticating? Just because Google is doing it? Well if you have anyone remotely technical in your team who understands authentication shcemes, then maybe you should bring them on here for a technical discuss.
I totally appreciate that Infusionsoft is a third rate software but still, when you charge customers money I think it is incumbent upon you to provide proper support and documentation. I do not think you will be surprised to know that your documentation is not a sincere effort at all and is mostly likely done by cheap outsourced labor that has no clue about your actual functionality. Quality of documentation apart, your API seems to be a real joke.
Jokes apart though, I am trying to access our own account using the API and I am bewildered out of my sleep to find that I need to create an app for that, get it approved etc. and still have no clue about where to find client id, secret etc.
I am tempted to throw out your system as a wasted investment and move on but in the interest of semi-decency I am putting my comment here. I would not be surprised if you do not understand the question here but if that is the case, please let me know
How do I stop email auto-responders after the removal of tags using PHP SDK?
this is some of the worst documentation I have ever seen, it is written for people who already know the product usage and has ZERO usable information for new users.
you have assumed everyone is using composer
the code examples, https://github.com/infusionsoft/API-Sample-Code/tree/master/PHP, have not been updated in 2 years
you have made a simple process overly complex THEN suggest using third party wrapper libraries that have less documentation than the crumbs you provide
Top left it says “Difficulty: Easy”. These sorts of authentications to get keys/tokens and refresh them etc. is a nightmare. Every app that has this sort of authentication takes ages just to get to be able to use it. I’ve spent over a day just trying to authenticate with the app before I can actually start building my app. I would change it to “Difficulty: Hard”. Your support on Github has been very good though and would not have been able to do it without that, as the documentation was not great. Refreshing the token is missing in the examples for example.
How to send shipping details like city ,state, country in time of order creation via API, such that it can show in order details section