Intro
This is an un-official Node SDK for interfacing the Autopilot API. You can view the REST api documentation here. Some cool features include:
- Pass a normal JSON object and it would figure out which ones are custom fields and which ones are not
- Automatically reformat keys to contain Autopilot data types along with all neccessary hyphens. E.g.
{'Foo Bar': true}
will re-format to{'boolean--Foo--Bar': true}
- Add/Update/Delete Contact
- Unsubscribe Contact from a list
- Create lists
- Add Contacts to lists
- Get all Segments
- Register/Unregister hooks etc...
NB: Still under development so some APIs may not be available yet.
Installation
> npm i -S autopilot-sdk
Usage
; const autopilot = '<API_KEY>';//=> autopilot instance
API
The Autopilot instance has instance members that access the scopes of the API. Namely: contacts
, lists
, journeys
, segments
, etc... Below is the list of the methods for all the scopes.
NB: All calls on the contact/contacts scope must have a contact_id
or email
member parameter. Find more in the Autopilot documentation.
contacts#save()
Parameters:
- data - An Object containing new/existing user details
Example:
const contactData = 'email': 'johndoe@example.com' 'Full Name': 'John Doe' 'Gender': 'male' 'age': 35; await autopilotcontacts;//=> { contact_id: 'person_32941749279223008202071' } // saving multiple contacts at onceconst multipleContactsData = email: 'test@example.com' FirstName: 'Seeker' LastName: 'Drew' 'Full Name': 'Seeker Drew' foo: true age: 21 email: 'test1@example.com' FirstName: 'Bill' LastName: 'Gates' 'Full Name': 'Bill Gates' foo: false age: 25 ;await autopilotcontacts;
contacts#get()
Parameters:
- args - This must be a email/contact_id string or an array of email/contact_ids to retrieve
Example:
// get contact data by emailconst contactByEmail = await autopilotcontacts; // get contact data by idconst contactById = await autopilotcontacts; // get list of contact data by either email or idconst contacts = await autopilotcontacts;
contacts#delete()
Parameters:
- emailOrId - As the name suggest, it must be an
email
orcontact_id
Example:
// NB: the delete API doesn't return any object. You'll know it failed when the promise fails.await autopilotcontacts;//=> undefined await autopilotcontacts;//=> undefined
contacts#unsubscribe()
Parameters:
- emailOrId - As the name suggest, it must be an
email
orcontact_id
to unsubscribe
Example:
await autopilotcontacts;//=> undefined