A third-party Node.js wrapper for Autopilot's REST API.
Example:
let Autopilot = require('autopilot-api');
let autopilot = new Autopilot('c5359558cf764d17bc49f13a87e8a56e');
let contact = { FirstName: 'Bob', LastName: 'Barker', Email: 'bob@priceisright.com' };
autopilot.contacts.upsert(contact)
.then(console.log)
.catch(console.error);
- Installation
- Usage
- Contacts
- Lists
- Smart Segments
- Journeys (via triggers)
- Account
- REST Hooks
- License
npm install autopilot-api --save
Begin by initializing with your API key:
let Autopilot = require('autopilot-api');
let autopilot = new Autopilot('c5359558cf764d17bc49f13a87e8a56e');
Now you will be able to interact with Autopilot resources as described below.
Optionally you can pass an endpoint to use. This can be useful in testing if you want to call the sandbox api.
let Autopilot = require('autopilot-api');
let autopilot = new Autopilot('c5359558cf764d17bc49f13a87e8a56e', 'https://private-anon-5efcbf2622-autopilot.apiary-mock.com/v1');
-
Method:
autopilot.contacts.upsert(data[, callback]) -
Parameters:
Name Type Required Description dataobjectorarrayYes The contact data to be upserted. If an array is provided, a bulk upsert is performed. callbackfunctionNo A callback function to be executed upon completion. -
Promise example:
let contact = { FirstName: 'Bob', LastName: 'Barker', Email: 'bob@priceisright.com' }; autopilot.contacts.upsert(contact) .then(console.log) .catch(console.error); -
Callback example:
let contact = { FirstName: 'Bob', LastName: 'Barker', Email: 'bob@priceisright.com' }; autopilot.contacts.upsert(contact, (err, response) => { if (err) { return console.error(err, response); } console.log(response); });
-
Method:
autopilot.contacts.get(id[, callback]) -
Parameters:
Name Type Required Description idstringYes Either the Autopilot contact_idor the contact's email addresscallbackfunctionNo A callback function to be executed upon completion. -
Promise example:
autopilot.contacts.get('bob@priceisright.com') .then(console.log) .catch(console.error); -
Callback example:
autopilot.contacts.get('bob@priceisright.com', (err, response) => { if (err) { return console.error(err, response); } console.log(response); });
-
Method:
autopilot.contacts.delete(id[, callback]) -
Parameters:
Name Type Required Description idstringYes Either the Autopilot contact_idor the contact's email addresscallbackfunctionNo A callback function to be executed upon completion. -
Promise example:
autopilot.contacts.delete('bob@priceisright.com') .then(console.log) .catch(console.error); -
Callback example:
autopilot.contacts.delete('bob@priceisright.com', (err, response) => { if (err) { return console.error(err, response); } console.log(response); });
-
Method:
autopilot.contacts.unsubscribe(id[, callback]) -
Parameters:
Name Type Required Description idstringYes Either the Autopilot contact_idor the contact's email addresscallbackfunctionNo A callback function to be executed upon completion. -
Promise example:
autopilot.contacts.unsubscribe('bob@priceisright.com') .then(console.log) .catch(console.error); -
Callback example:
autopilot.contacts.unsubscribe('bob@priceisright.com', (err, response) => { if (err) { return console.error(err, response); } console.log(response); });
-
Method:
autopilot.contacts.fields([callback]) -
Parameters:
Name Type Required Description callbackfunctionNo A callback function to be executed upon completion. -
Promise example:
autopilot.contacts.fields() .then(console.log) .catch(console.error); -
Callback example:
autopilot.contacts.fields((err, response) => { if (err) { return console.error(err, response); } console.log(response); });
-
Method:
autopilot.lists.list([callback]) -
Parameters:
Name Type Required Description callbackfunctionNo A callback function to be executed upon completion. -
Promise example:
autopilot.lists.list() .then(console.log) .catch(console.error); -
Callback example:
autopilot.lists.list((err, response) => { if (err) { return console.error(err, response); } console.log(response); });
-
Method:
autopilot.lists.insert(name[, callback]) -
Parameters:
Name Type Required Description namestringYes The name for a new list. callbackfunctionNo A callback function to be executed upon completion. -
Promise example:
autopilot.lists.insert('Animal Rights Supporters') .then(console.log) .catch(console.error); -
Callback example:
autopilot.lists.insert('Animal Rights Supporters', (err, response) => { if (err) { return console.error(err, response); } console.log(response); });
-
Method:
autopilot.lists.roster(id[, bookmark, callback]) -
Parameters:
Name Type Required Description idstringYes The idof the list to query.bookmarkstringNo If there are more contacts on the list than have been returned, the bookmark will allow you to access the next group of contacts. callbackfunctionNo A callback function to be executed upon completion. -
Promise example:
autopilot.lists.roster('contactlist_06444749-9C0F-4894-9A23-D6872F9B6EF8') .then(console.log) .catch(console.error); -
Callback example:
autopilot.lists.roster('contactlist_06444749-9C0F-4894-9A23-D6872F9B6EF8', () => { if (err) { return console.error(err, response); } console.log(response); });
-
Method:
autopilot.lists.has(listId, contactId[, callback]) -
Parameters:
Name Type Required Description listIdstringYes The idof the list to query.contactIdstringYes Either the Autopilot contact_idor the contact's email address.callbackfunctionNo A callback function to be executed upon completion. -
Promise example:
autopilot.lists.has('contactlist_06444749-9C0F-4894-9A23-D6872F9B6EF8', 'bob@priceisright.com') .then(console.log) .catch(console.error); -
Callback example:
autopilot.lists.has('contactlist_06444749-9C0F-4894-9A23-D6872F9B6EF8', 'bob@priceisright.com', (err, response) => { if (err) { return console.error(err, response); } console.log(response); });
-
Method:
autopilot.lists.add(listId, contactId[, callback]) -
Parameters:
Name Type Required Description listIdstringYes The idof the list to query.contactIdstringYes Either the Autopilot contact_idor the contact's email address.callbackfunctionNo A callback function to be executed upon completion. -
Promise example:
autopilot.lists.add('contactlist_06444749-9C0F-4894-9A23-D6872F9B6EF8', 'bob@priceisright.com') .then(console.log) .catch(console.error); -
Callback example:
autopilot.lists.add('contactlist_06444749-9C0F-4894-9A23-D6872F9B6EF8', 'bob@priceisright.com', (err, response) => { if (err) { return console.error(err, response); } console.log(response); });
-
Method:
autopilot.lists.remove(listId, contactId[, callback]) -
Parameters:
Name Type Required Description listIdstringYes The idof the list to query.contactIdstringYes Either the Autopilot contact_idor the contact's email address.callbackfunctionNo A callback function to be executed upon completion. -
Promise example:
autopilot.lists.remove('contactlist_06444749-9C0F-4894-9A23-D6872F9B6EF8', 'bob@priceisright.com') .then(console.log) .catch(console.error); -
Callback example:
autopilot.lists.remove('contactlist_06444749-9C0F-4894-9A23-D6872F9B6EF8', 'bob@priceisright.com', (err, response) => { if (err) { return console.error(err, response); } console.log(response); });
-
Method:
autopilot.smartSegments.list([callback]) -
Parameters:
Name Type Required Description callbackfunctionNo A callback function to be executed upon completion. -
Promise example:
autopilot.smartSegments.list() .then(console.log) .catch(console.error); -
Callback example:
autopilot.smartSegments.list((err, response) => { if (err) { return console.error(err, response); } console.log(response); });
-
Method:
autopilot.smartSegments.roster(id[, bookmark, callback]) -
Parameters:
Name Type Required Description idstringYes The idof the smart segment to query.bookmarkstringNo If there are more contacts on the smart segment than have been returned, the bookmark will allow you to access the next group of contacts. callbackfunctionNo A callback function to be executed upon completion. -
Promise example:
autopilot.smartSegments.roster('contactlist_06444749-9C0F-4894-9A23-D6872F9B6EF8') .then(console.log) .catch(console.error); -
Callback example:
autopilot.smartSegments.roster('contactlist_06444749-9C0F-4894-9A23-D6872F9B6EF8', (err, response) => { if (err) { return console.error(err, response); } console.log(response); });
-
Method:
autopilot.journeys.add(triggerId, contactId[, callback]) -
Parameters:
Name Type Required Description triggerIdstringYes The idof the trigger associated with the Journey we're adding to.contactIdstringYes Either the Autopilot contact_idor the contact's email address.callbackfunctionNo A callback function to be executed upon completion. -
Promise example:
autopilot.lists.add('0001', 'bob@priceisright.com') .then(console.log) .catch(console.error); -
Callback example:
autopilot.lists.add('0001', 'bob@priceisright.com', (err, response) => { if (err) { return console.error(err, response); } console.log(response); });
-
Method:
autopilot.journeys.list([callback]) -
Parameters:
Name Type Required Description callbackfunctionNo A callback function to be executed upon completion. -
Promise example:
autopilot.journeys.list() .then(console.log) .catch(console.error); -
Callback example:
autopilot.journeys.list((err, response) => { if (err) { return console.error(err, response); } console.log(response); });
-
Method:
autopilot.account.get([callback]) -
Parameters:
Name Type Required Description callbackfunctionNo A callback function to be executed upon completion. -
Promise example:
autopilot.account.get() .then(console.log) .catch(console.error); -
Callback example:
autopilot.account.get((err, response) => { if (err) { return console.error(err, response); } console.log(response); });
-
Method:
autopilot.restHooks.list([callback]) -
Parameters:
Name Type Required Description callbackfunctionNo A callback function to be executed upon completion. -
Promise example:
autopilot.restHooks.list() .then(console.log) .catch(console.error); -
Callback example:
autopilot.restHooks.list((err, response) => { if (err) { return console.error(err, response); } console.log(response); });
-
Method:
autopilot.restHooks.register(event, targetUrl, [callback]) -
Parameters:
Name Type Required Description eventstringYes The event name that you wish to be told about. targetUrlstringYes The URL in your API which you want Autopilot to POST to when the event occurs. callbackfunctionNo A callback function to be executed upon completion. -
Promise example:
autopilot.restHooks.register('contact_added', 'http://www.priceisright.com/tracking') .then(console.log) .catch(console.error); -
Callback example:
autopilot.restHooks.register('contact_added', 'http://www.priceisright.com/tracking', (err, response) => { if (err) { return console.error(err, response); } console.log(response); })
-
Method:
autopilot.restHooks.unregister(hookId, [callback]) -
Parameters:
Name Type Required Description hookIdstringYes The idof the hook to unregister.callbackfunctionNo A callback function to be executed upon completion. -
Promise example:
autopilot.restHooks.unregister('hook_ED75BA78-2405-4564-B24C-F2B8F936C7C6') .then(console.log) .catch(console.error); -
Callback example:
autopilot.restHooks.unregister('hook_ED75BA78-2405-4564-B24C-F2B8F936C7C6', (err, response) => { if (err) { return console.error(err, response); } console.log(response); });
-
Method:
autopilot.restHooks.deleteAll([callback]) -
Parameters:
Name Type Required Description callbackfunctionNo A callback function to be executed upon completion. -
Promise example:
autopilot.restHooks.deleteAll() .then(console.log) .catch(console.error); -
Callback example:
autopilot.restHooks.deleteAll((err, response) => { if (err) { return console.error(err, response); } console.log(response); });
Released under MIT.