Infusionsoft API
A promise-driven, fluent-style Node.js wrapper for the XML-RPC Infusionsoft API.
Write badass Infusionsoft apps on the server that are fully and natively asynchronous.
It's pretty dope.
Usage
Install via npm
:
$ npm install infusionsoft-api
Do cool stuff:
var api = ; var infusionsoft = 'myapp' 'MY_API_KEY'; infusionsoftContacts ;
You can also use the API Services directly:
infusionsoftContactService ;
Awesome.
Promises
All asynchronous methods return a Promise that represents the eventual value that will be returned.
Promises are glorious and make writing heavily asynchronous code much less awful than it would otherwise be.
See the More Examples section to see them in action.
API Scraper
This project creates interfaces and classes for the API services and tables via
the grunt-infusionsoft grunt
plugin. To recreate the generated files, run grunt infusionsoft
.
Check out the infusionsoft
directory to see the output.
More Examples
All examples use infusionsoft
as an instantiated DataContext with your app
name and API key. ie:
var infusionsoft = 'myAppName' 'MY_API_KEY';
Get monthly revenue from a particular month
infusionsoftPayments ;
Login a user and get their info
And an example of using the fail
method to catch any problems.
infusionsoftDataService ;
Get all invoices for a specific month, grouped by product
Uses underscore.
infusionsoftInvoices ;
Same as above, but use the spread
function to wait on 2 promises to get the
corresponding product names. The API hits for querying both the Product
table
and the Invoice
table will actually fire off at the same time.
Hashtag asynchronous.
var products = infusionsoftProducts;var invoices = infusionsoftInvoices ; Q;
From an email address, get a contact's tags
sdkContacts ;
Get the full Product Category Name for all subscription plans
Okay, take a deep breath. We can do (inner) joins. We fake it though... the
inner
part of the join has to be loaded entirely and then we do a O(n^2)
iteration to make it, but we can still do it. If the inner
is cheap, this
isn't too bad. Especially when the SDK will handle loading, paging, waiting,
etc... all for you.
Syntax (stolen from C#'s LINQ):
join
(innerQueryable
, outerKey
, innerKey
, selectorFn
)
Let's do this:
var pc = infusionsoftProductCategories;var pca = infusionsoftProductCategoryAssigns;var plans = infusionsoftSubscriptionPlans; // Join the categories onto itself for creating the full category name// (category parent name + category name)var categories = pc ; var subPlans = plans // Join the sub plan (which only has product Id) onto the PCA table to get // the product category ID // Join our categories object we made above onto the projection from the // most recent join to get the full category name + subscription plan Id ; subPlans;
What happens magically behind the scenes is pretty nice. When we call
toArray()
at the end, we first query the SubscriptionPlan table (aliased as
plans
). It then knows we need to join the ProductCategoryAssign
table on
there, so it fetches that (which may be more than one page). It finally gets
the ProductCategory
table (in its entirety), and joins them all up.
The syntax looks nasty, but that is somewhat unavoidable with a join
function.
License
Copyright 2013 Brandon Valosek
Infusionsoft API is released under the MIT license.