Skip to content

snamoah/autopilot-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

import Autopilot from 'autopilot-sdk';

const autopilot = new 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': '[email protected]',
  'Full Name': 'John Doe',
  'Gender': 'male',
  'age': 35,
};

await autopilot.contacts.save(contactData);
//=> { contact_id: 'person_32941749279223008202071' }

// saving multiple contacts at once
const multipleContactsData = [
  {
    email: '[email protected]',
    FirstName: 'Seeker',
    LastName: 'Drew',
    'Full Name': 'Seeker Drew',
    foo: true,
    age: 21,
  },
  {
    email: '[email protected]',
    FirstName: 'Bill',
    LastName: 'Gates',
    'Full Name': 'Bill Gates',
    foo: false,
    age: 25,
  },
];
await autopilot.contacts.save(multipleContactsData);

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 email
const contactByEmail = await autopilot.contacts.get('[email protected]');

// get contact data by id
const contactById = await autopilot.contacts.get('person_9EAF39E4-9AEC-4134-964A-D9D8D54162E7');

// get list of contact data by either email or id
const contacts = await autopilot.contacts.get(['[email protected]', 'person_9EAF39E4-9AEC-4134-964A-D9D8D54162E7']);

contacts#delete()

Parameters:

  • emailOrId - As the name suggest, it must be an email or contact_id

Example:

// NB: the delete API doesn't return any object. You'll know it failed when the promise fails.
await autopilot.contacts.delete('person_9EAF39E4-9AEC-4134-964A-D9D8D54162E7');
//=> undefined

await autopilot.contacts.delete('[email protected]');
//=> undefined

contacts#unsubscribe()

Parameters:

  • emailOrId - As the name suggest, it must be an email or contact_id to unsubscribe

Example:

await autopilot.contacts.unsubscribe('[email protected]');
//=> undefined