-
Notifications
You must be signed in to change notification settings - Fork 52
Examples
This project is production quality. It is being used in dozens of production applications.
This SDK is designed to run on PHP 5.1 or greater.
Copy the Infusionsoft directory to your project.
Copy the config.sample.php
file to config.php
and put in your Infusionsoft app hostname and api key.
Add any custom fields you are going to use via the API by adding a line to your config.php file. For example, to add the custom field LeadScore to Contact:
Infusionsoft_Contact::addCustomField('_LeadScore');
include('Infusionsoft/infusionsoft.php');
$contact = new Infusionsoft_Contact();
$contact->FirstName = 'John';
$contact->LastName = 'Doe';
$contact->save();
include('Infusionsoft/infusionsoft.php');
//In the Infusionsoft API, Opportunities are called leads.
$opportunity = new Infusionsoft_Lead();
$opportunity->ContactID = $contact->Id;
$opportunity->OpportunityTitle = 'A Sweet Chance to make Millions of Dollars!';
$opportunity->OpportunityNotes = 'I saw a sign next to the road that said "Real Estate Apprentice Wanted"';
$opportunity->save();
// Lookup sales person in InfusionSoft by his email so we can use his ID later.
$infusionSoftUserSearch = Infusionsoft_DataService::query( new Infusionsoft_User(), array( 'Email' => 'salesagent@mycomp.com' ) );
$infusionSoftUser = array_shift( $infusionSoftUserSearch );
$contactAction = new Infusionsoft_ContactAction();
$contactAction->ContactId = $contact->Id;
$contactAction->UserID = $infusionSoftUser->Id;
$contactAction->CompletionDate = date('Ymj\TG:i:s');
$contactAction->ActionDescription = 'My Note Title';
$contactAction->CreationNotes = 'My Note Description';
$contactAction->save();
include('Infusionsoft/infusionsoft.php');
$contact = new Infusionsoft_Contact($id);
$contact->FirstName = 'John Boy';
$contact->LastName = 'Walton';
$contact->save();
<form>
ContactId: <input type="text" name="ContactId" value="<?php if(isset($_REQUEST['ContactId'])) echo $_REQUEST['ContactId']; ?>" />
<input type="submit"/>
</form><br/>
<?php
include('../infusionsoft.php');
if(isset($_REQUEST['ContactId'])){
$contact = new Infusionsoft_Contact($_REQUEST['ContactId']);
$contact->_LeadScore = $contact->_LeadScore + 1;
$contact->save();
echo 'Lead Score for Contact: ' . $contact->FirstName . ' ' . $contact->LastName . ' is now: ' . $contact->_LeadScore;
}
$customField = Infusionsoft_CustomFieldService::getCustomField(new Infusionsoft_Contact(), '_LeadScore');
$customField->addValue('New DropDown Option');
$customField->save();
To search a table for records, you'll need to use Infusionsoft_DataService::query()
, or DataService::findByField()
(not recommended due to performance issues).
For example, if you wanted to pull the first 1,000 order items for a specific order you could do this:
// The ID for the specific order. This is passed as $_GET['orderId'] to
// shopping cart and order form thank you pages.
$orderId = 123;
$orderItems = Infusionsoft_DataService::query(new Infusionsoft_OrderItem(), array('OrderId' => $orderId));
foreach($orderItems as $orderItem) {
// Each $orderItem will be an Infusionsoft_OrderItem object
}
Or to get a specific contact record:
$contacts = Infusionsoft_DataService::query(new Infusionsoft_Contact(), array('Id' => 2));
$contact = array_shift($contacts);
$contact = new Infusionsoft_Contact();
$contact->FirstName = 'John';
$contact->LastName = 'Doe';
$contact->save();
$invoiceId = Infusionsoft_InvoiceService::createBlankOrder($contact->Id, "An Order", date('Ymd\TH:i:s'));
Infusionsoft_InvoiceService::addOrderItem($invoiceId, $productId, 4, 3.99, 1, 'Order Item', '');
Infusionsoft_InvoiceService::addManualPayment($invoiceId, 3.99, date('Ymd\TH:i:s'), 'API', 'A Manual Payment from the API');
First, create a credit card
$creditCard = new Infusionsoft_CreditCard();
$creditCard->ContactId = $contact->Id;
$creditCard->BillName = $contact->FirstName . ' ' . $contact->LastName;
$creditCard->FirstName = $contact->FirstName;
$creditCard->LastName = $contact->LastName;
$creditCard->CardNumber = 1234567890123456;
$creditCard->CVV2 = 197;
$creditCard->CardType = 'Visa';
$creditCard->Status = 3; //0: Unknown, 1: Invalid, 2: Deleted, 3: Valid/Good, 4: Inactive
$creditCard->save();
Second, create the Subscription Plan
$subscriptionPlan = new Infusionsoft_SubscriptionPlan();
$subscriptionPlan->ProductId = 5;
$subscriptionPlan->Cycle = 3;
$subscriptionPlan->Frequency = 1;
$subscriptionPlan->Prorate = 0;
$subscriptionPlan->Active = 1;
$subscriptionPlan->PlanPrice = 499.99;
$subscriptionPlan->save();
Third, use addRecurringOrder, create an Invoice, & charge the Invoice
// addReccuringOrder($contactId, $allowDuplicate, $cProgramId, $qty, $price, $allowTax, $merchantAccountId, $creditCardId, $affiliateId, $daysTillCharge, Infusionsoft_App $app = null)
$subscriptionId = Infusionsoft_InvoiceService::addRecurringOrder($contact->Id, false, $subscriptionPlan->Id, 1, 19.99, false, 3, $creditCard->Id, 0, 0);
// Create an invoice for the recurring order.
$invoiceId = Infusionsoft_InvoiceService::createInvoiceForRecurring($subscriptionId);
// Charge the invoice
// chargeInvoice($invoiceId, $notes, $creditCardId, $merchantAccountId, $bypassCommissions, Infusionsoft_App $app = null)
$charge = Infusionsoft_InvoiceService::chargeInvoice($invoiceId, 'Test payment', $creditCard->Id, 3, false);
Infusionsoft_ContactService::runActionSequence($contactId, $actionSetId);
Only certain custom field types have values. If you try to get the list of values for a custom field that doesn't have values, you will get an exception.
//$customField will be an instance of an Infusionsoft_DataFormField
$customField = Infusionsoft_CustomFieldService::getCustomField(new Infusionsoft_Contact(), '_SomeCustomField');
$fieldValues = $customField->getValues();
Only certain custom field types have values. If you try to add a value to a custom field that doesn't have values, you will get an exception.
//$customField will be an instance of an Infusionsoft_DataFormField
$customField = Infusionsoft_CustomFieldService::getCustomField(new Infusionsoft_Contact(), '_SomeCustomField');
$customField->addValue('Some Value');
$customField->save();
Only certain custom field types have values. If you try to add a value to a custom field that doesn't have values, you will get an exception.
//$customField will be an instance of an Infusionsoft_DataFormField
$customField = Infusionsoft_CustomFieldService::getCustomField(new Infusionsoft_Contact(), '_SomeCustomField');
$customField->removeValue('Some Value');
$customField->save();
Get all Ids from a saved contact search.
$page = 0;
do{
$results = Infusionsoft_SearchService::getSavedSearchResults($saved_search_id, $saved_search_user_id, $page, array('Id'));
$all_ids = array_merge($results, $all_ids);
$page++;
}while(count($results) > 0);
var_dump($all_ids);
Upload /www/picture.jpg
to your filebox.
$filename = '/www/picture.jpg';
$data = base64_encode(file_get_contents($filename));
Infusionsoft_FileService::uploadFile(null, 'picture.jpg', $data);
To upload a file to a specific contact's filebox, specify the contact ID (in this example, 8):
$filename = '/www/picture.jpg';
$data = base64_encode(file_get_contents($filename));
Infusionsoft_FileService::uploadFile(8, 'picture.jpg', $data);
The Infusionsoft API uses the term groups instead of tags. Use the ContactService to add a tag to an existing contact:
$contactID = 40; // A valid ID for an existing contact
$groupID = 119; // A valid ID for an existing tag
Infusionsoft_ContactService::addToGroup($contactID, $groupID);
Most of the methods in the sdk take an $app object as the final parameter, you can pass in which app you want to use to get things.
WARNING: To use custom fields and multiapps, both apps either have to have identical custom fields, or you have to manually add and remove custom fields from objects before fetching or saving. MultiApp support is kind of a fringe benefit, so I wouldn't hold my breath for a fix for this.
$app1 = new Infusionsoft_App('ii130.infusionsoft.com', 'key');
$app2 = new Infusionsoft_App('jd567.infusionsoft.com', 'key');
$contactsFromApp1 = Infusionsoft_DataService::query(new Infusionsoft_Contact(), array(...), 1000, 0, false, $app1);
$contactsFromApp2 = Infusionsoft_DataService::query(new Infusionsoft_Contact(), array(...), 1000, 0, false, $app2);
$contactFromApp1 = array_shift($contactsFromApp1);
$contactFromApp1->Phone1 = '555-555-5555';
$contactFromApp2 = array_shift($contactsFromApp2);
$contactFromApp1->Email = 'bob@bob.com';
//Objects automatically keep track of what app they are from, so when you save them, it goes to the right app.
$contactFromApp1->save();
$contactFromApp2->save();
###LinkedContactTypes
include('../infusionsoft.php');
$linkedContactTypes = Infusionsoft_DataService::query(new Infusionsoft_LinkedContactType(), array('Id' => '%'));
var_dump($linkedContactTypes);