One of the hidden gems in the Keap suite of software is the API. The Keap API enables third-party applications to communicate with Keap and process, update, and destroy data for a wide variety of uses. You can do things like manage contacts, place orders, send messages, and most other things available for use in the Keap software.
Keap officially supports the PHP library we created in-house. In addition, there are a number of third party helper libraries created by members of the community that may be useful to you. Many of these libraries are open source, so we encourage you to get into contact with their creators if you find bugs or have ideas for feature requests.
See Available Helper Libraries
The Keap API uses a fairly standard implementation of OAuth 2.0 in order to provide authentication to all API endpoints. In the past, the Infusionsoft API has relied on a simple token based system; while those tokens will remain active until some date in the future for the XML-RPC API, any new implementations and all requests to the REST API will be required to use OAuth 2.0. Rather than re-explain OAuth again, it is more useful to provide a series of documents that have already been created and demonstrate the OAuth protocol, how to implement it in your code, how to troubleshoot, and how to ease development. Before that, though, it is important to have the authorization destinations and necessary details.
The first step in the OAuth flow is to redirect the user to Keap in order to authorize your application for access. The URL you generate here is where you first send your user in order for them to log in and continue the OAuth flow.
Redirect users to https://signin.infusionsoft.com/app/oauth/authorize
along with the required parameters in order to start the OAuth exchange.
GET https://signin.infusionsoft.com/app/oauth/authorize
Begins the OAuth flow by asking the user to choose an Infusionsoft account to authenticate with.
curl https://signin.infusionsoft.com/app/oauth/authorize
require("../../src/isdk.php");
$app = new iSDK();
$app->setClientId('CLIENTID');
$app->setSecret('CLIENTSECRET');
echo "<p>Click the link below to allow my application to access your Infusionsoft application.</p>";
echo '<a href="'.$app->getAuthorizationURL().'">Authorize My Application</a>';
$url = $infusionsoft->getAuthorizationUrl();
echo '<a href="' . $url . '">Click here to authorize</a>';
Using the code
URL parameter returned from the authorization callback, your application can request an access token and refresh token from Keap.
Requesting an access token requires you to POST
to https://api.infusionsoft.com/token
curl https://api.infusionsoft.com/token -X POST -d card=token_id
{
"token_type": "bearer",
"access_token": "axxxxx",
"expires_in": 3600,
"refresh_token": "rxxxxx",
"scope":"full|example.infusionsoft.com"
}
require("../../src/isdk.php");
$app = new iSDK();
if(isset($_GET['code'])){
$app->setClientId('CLIENTID');
$app->setSecret('CLIENTSECRET');
$app->authorize($_GET['code']);
$app->refreshAccessToken();
}
$infusionsoft->requestAccessToken($_GET['code']);
After your access token expires, you'll use the refresh token that was provided when your access token was initially granted to request a new access token.
Note: Once a Refresh Token is used to receive a new Access Token, you will be returned a new Refresh Token as well, which will need to be persisted in order to request the next access token.
Refreshing an access token requires you to POST
to https://api.infusionsoft.com/token
POST /token
$infusionsoft->refreshAccessToken();
$infusionsoft = new InfusionsoftInfusionsoft(array(
'clientId' => 'CLIENT_ID',
'clientSecret' => 'CLIENT_SECRET',
'redirectUri' => 'REDIRECT_URL',
));
// retrieve the existing token object from storage
$infusionsoft->setToken($yourStoredToken);
$infusionsoft->refreshAccessToken();
POST /token
$infusionsoft->refreshAccessToken();
$infusionsoft = new InfusionsoftInfusionsoft(array(
'clientId' => 'CLIENTID',
'clientSecret' => 'CLIENTSECRET',
'redirectUri' => 'https://example.com/callback',
));
// retrieve the existing token object from storage
$infusionsoft->setToken($yourStoredToken);
return $infusionsoft->refreshAccessToken();