PHP code example of infusionsoft / php-sdk

1. Go to this page and download the library: Download infusionsoft/php-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

infusionsoft / php-sdk example snippets



if(empty(session_id();)) session_start();

soft(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>';
}



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

// MAKE INFUSIONSOFT REQUEST



//
// 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'));


 $tasks = $infusionsoft->tasks()->all();
 

 $task = $infusionsoft->tasks()->find($taskId);
 

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

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

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

 $task->title = 'A better task title';
 $task->save();
 

 $task->delete();
 

 $tasks = $infusionsoft->tasks()->sync($syncId);
 



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

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


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

$infusionsoft->setDebug(true);

$infusionsoft->getLogs();

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

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

$infusionsoft->setHttpLogAdapter($logger);

composer 
 json
{
    "fusionsoft/php-sdk": "1.6.*"
    }
}

php artisan vendor:publish --provider="Infusionsoft\FrameworkSupport\Laravel\InfusionsoftServiceProvider"

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

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

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

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