2017 © Pedro Peláez
 

library php-sdk

PHP SDK for the Infusionsoft

image

infusionsoft/php-sdk

PHP SDK for the Infusionsoft

  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 66 Forks
  • 20 Open issues
  • 29 Versions
  • 15 % Grown

The README.md

Infusionsoft PHP SDK

[!WARNING] ⚠️ Deprecated This SDK is no longer actively maintained. Please migrate to the replacement: keap-sdk-php, available on Packagist., (*1)

You can use the Migration guide from infusionsoft/php-sdk., (*2)

Total Downloads Latest Stable Version, (*3)

Version Notes

This version implements RESTful endpoints, a new version of Guzzle, and a restructured request handler., (*4)

As of version 1.6, PHP 8.1+ is required., (*5)

Breaking Change

With the Guzzle 7 upgrade, there was a refactor on the request function name in Infusionsoft\Http\ClientInterface. If you created a custom HttpClient, you'll need to update to use the new function name of call, (*6)

If you use the Contacts, Orders or Products services, there are now two different classes handling each service - one for REST, one for XML-RPC. This version of the SDK will load the REST class by default. If you still need the XML-RPC class, pass 'xml' as an argument when requesting the object: $infusionsoft->orders('xml')', (*7)

Kudos to toddstoker and mattmerrill for their contributions to this release., (*8)

Install

Using the composer CLI:, (*9)

composer require infusionsoft/php-sdk

Or manually add it to your composer.json:, (*10)

``` json { "require": { "infusionsoft/php-sdk": "1.6.*" } }, (*11)


## Authentication Currently Keap supports two types of authentication for our APIs: the OAuth2 Access Code Grant and API Keys. Developers of third-party integrations should always use our OAuth2 authentication, but developers building integrations for a single tenant may find the use of API Keys much simpler. ### OAuth2 Access Code Grant The client ID and secret are the key and secret for your OAuth2 application found at the [Infusionsoft Developers](https://keys.developer.keap.com) website. ```php if(empty(session_id();)) session_start(); require_once 'vendor/autoload.php'; $infusionsoft = new \Infusionsoft\Infusionsoft(array( 'clientId' => 'XXXXXXXXXXXXXXXXXXXXXXXX', 'clientSecret' => 'XXXXXXXXXX', 'redirectUri' => 'http://example.com/', )); // If the serialized token is available in the session storage, we tell the SDK // to use that token for subsequent requests. if (isset($_SESSION['token'])) { $infusionsoft->setToken(unserialize($_SESSION['token'])); } // If we are returning from Infusionsoft we need to exchange the code for an // access token. if (isset($_GET['code']) and !$infusionsoft->getToken()) { $_SESSION['token'] = serialize($infusionsoft->requestAccessToken($_GET['code'])); } if ($infusionsoft->getToken()) { // Save the serialized token to the current session for subsequent requests $_SESSION['token'] = serialize($infusionsoft->getToken()); // MAKE INFUSIONSOFT REQUEST } else { echo '<a href="' . $infusionsoft->getAuthorizationUrl() . '">Click here to authorize</a>'; }

API Keys

API Keys are a "password" for your data in an application and should always be treated like a dangerous secret., (*12)

In our UI you will find an API Settings screen which divides API Keys into two distinct categories: * Personal Access Tokens, which are scoped to your own user account and can only see and manipulate the data you have access to. * Service Account Keys, which can only be authorized by an Administrator and have full access to the data stored in the application., (*13)

For additional information on how to authorize and use PATs and SAKs please see our developer documentation., (*14)

require_once 'vendor/autoload.php';

$infusionsoft = new \Infusionsoft\Infusionsoft(array(
  'apikey' => $APIKeyRetrievedFromCredentialStorage,
));

// MAKE INFUSIONSOFT REQUEST

Making XML-RPC Requests

require_once 'vendor/autoload.php';

//
// Setup your Infusionsoft object here, then set your token either via the request or from storage
// As of v1.3 contacts defaults to rest
$infusionsoft->setToken($myTokenObject);

$infusionsoft->contacts('xml')->add(array('FirstName' => 'John', 'LastName' => 'Doe'));

Making REST Requests

The PHP SDK is setup to allow easy access to REST endpoints. In general, a single result is returned as a Class representing that object, and multiple objects are returned as an Infusionsoft Collection, which is simply a wrapper around an array of results making them easier to manage., (*15)

The standard REST operations are mapped to a series of simple functions. We'll use the Tasks service for our examples, but the operations below work on all documented Infusionsoft REST services., (*16)

To retrieve all tasks:, (*17)

php $tasks = $infusionsoft->tasks()->all();, (*18)

To retrieve a single task:, (*19)

php $task = $infusionsoft->tasks()->find($taskId);, (*20)

To query only completed tasks:, (*21)

php $tasks = $infusionsoft->tasks()->where('status', 'completed')->get();, (*22)

You can chain where() as many times as you'd like, or you can pass an array:, (*23)

php $tasks = $infusionsoft->tasks()->where(['status' => 'completed', 'user_id' => '45'])->get();, (*24)

To create a task: php $task = $infusionsoft->tasks()->create([ 'title' => 'My First Task', 'description' => 'Better get it done!' ]);, (*25)

Then update that task: php $task->title = 'A better task title'; $task->save();, (*26)

And finally, to delete the task: php $task->delete();, (*27)

Several REST services have a /sync endpoint, which we provide a helper method for: php $tasks = $infusionsoft->tasks()->sync($syncId);, (*28)

This returns a list of tasks created or updated since the sync ID was last generated., (*29)

require_once 'vendor/autoload.php';

//
// Setup your Infusionsoft object here, then set your token either via the request or from storage
//
$infusionsoft->setToken($myTokenObject);

$infusionsoft->tasks()->find('1');

Dates

DateTime objects are used instead of a DateTime string where the date(time) is a parameter in the method., (*30)

$datetime = new \DateTime('now',new \DateTimeZone('America/New_York'));

Debugging

To enable debugging of requests and responses, you need to set the debug flag to try by using:, (*31)

$infusionsoft->setDebug(true);

Once enabled, logs will by default be written to an array that can be accessed by:, (*32)

$infusionsoft->getLogs();

You can utilize the powerful logging plugin built into Guzzle by using one of the available adapters. For example, to use the Monolog writer to write to a file:, (*33)

use Monolog\Handler\StreamHandler;
use Monolog\Logger;

$logger = new Logger('client');
$logger->pushHandler(new StreamHandler('infusionsoft.log'));

$infusionsoft->setHttpLogAdapter($logger);

Testing

``` bash $ phpunit, (*34)


## Laravel Framework Support ### Laravel < 5.5 In config/app.php, register the service provider

Infusionsoft\FrameworkSupport\Laravel\InfusionsoftServiceProvider::class,, (*35)


Register the Facade (optional)

'Infusionsoft' => Infusionsoft\FrameworkSupport\Laravel\InfusionsoftFacade::class, (*36)


### Laravel >= 5.5 In Laravel 5.5, package auto-discovery was added. The service provider and facade will be detected for you. Continue by publishing the vendor assets and adding your env variables. Publish the config

php artisan vendor:publish --provider="Infusionsoft\FrameworkSupport\Laravel\InfusionsoftServiceProvider", (*37)


Set your env variables

INFUSIONSOFT_CLIENT_ID=xxxxxxxx INFUSIONSOFT_SECRET=xxxxxxxx INFUSIONSOFT_REDIRECT_URL=http://localhost/auth/callback, (*38)


Access Infusionsoft from the Facade or Binding

$data = Infusionsoft::data()->query("Contact",1000,0,['Id' => '123'],['Id','FirstName','LastName','Email'], 'Id', false);, (*39)

$data = app('infusionsoft')->data()->query("Contact",1000,0,['Id' => '123'],['Id','FirstName','LastName','Email'], 'Id', false);, (*40)


## Lumen Service Provider In bootstrap/app.php, register the service provider

$app->register(Infusionsoft\FrameworkSupport\Lumen\InfusionsoftServiceProvider::class);, (*41)


Set your env variables (make sure you're loading your env file in app.php)

INFUSIONSOFT_CLIENT_ID=xxxxxxxx INFUSIONSOFT_SECRET=xxxxxxxx INFUSIONSOFT_REDIRECT_URL=http://localhost/auth/callback, (*42)


Access Infusionsoft from the Binding

$data = app('infusionsoft')->data()->query("Contact",1000,0,['Id' => '123'],['Id','FirstName','LastName','Email'], 'Id', false);, (*43)


## SDK Development You can install the Composer dependencies without installing Composer:

docker compose run composer, (*44)


You can access the samples by spinning up the Docker container for the Composer dependencies:

docker compose up -d, (*45)


Tests can be executed without installing PHP in the host environment (while the main container is running):

docker exec -it infusionsoft-php /var/www/html/vendor/bin/phpunit tests ```, (*46)

If using Docker for Windows, please see .env for additional details., (*47)

Contributing

Please see CONTRIBUTING for details., (*48)

License

The MIT License (MIT). Please see License File for more information., (*49)

The Versions

24/04 2017
22/06 2015

5.3.x-dev

5.3.9999999.9999999-dev https://developer.infusionsoft.com

Beta PHP SDK for the Infusionsoft

  Sources   Download

MIT

The Requires

 

The Development Requires

sdk infusionsoft

22/06 2015
21/11 2014

1.0.0-beta2

1.0.0.0-beta2 https://developer.infusionsoft.com

Beta PHP SDK for the Infusionsoft

  Sources   Download

MIT

The Requires

 

The Development Requires

sdk infusionsoft

14/05 2014

1.0.0-beta1

1.0.0.0-beta1 https://developer.infusionsoft.com

Beta PHP SDK for the Infusionsoft

  Sources   Download

MIT

The Requires

 

The Development Requires

sdk infusionsoft