npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

icontact-api

v0.3.1

Published

Promisified interface for the iContact and iContact Pro REST APIs

Downloads

123

Readme

iContact API

icontact-api provides a pomisified interface for iContact and iContact Pro's REST APIs.

To install icontact-api, use npm:

$ npm install icontact-api

Examples

Instantiating an IContactAPI Object

import IContactAPI from 'icontact-api';

const iContactAPI = new IContactAPI('my app id', 'my username', 'my password');
iContactAPI.setAccountId(9999999);
iContactAPI.setClientFolderId(9999);

iContact and iContact Pro

By default, the IContactAPI object will attempt to connect to the iContact Pro REST API. To instantiate an object that will connect to regular iContact, pass false for the optional fourth constructor parameter:

const iContactAPI = new IContactAPI('my app id', 'my username', 'my password', false);

Sandbox Account

To connect to an iContact Sandbox account, pass true for the optional fifth constructor parameter.

const iContactAPI = new IContactAPI('my app id', 'my username', 'my password', false, true);

Note that iContact Pro doesn't have a sandbox and the fifth parameter will be ignored.

Searching for a Contact

// search by contactId
iContactAPI.getContacts({ contactId: 23 }).then((results) => {
  console.log(results);
});

// search by state and firstName with pattern matching
iContactAPI.getContacts({ state: 'MD', firstName: 'John*' }).then((results) => {
  console.log(results);
});

Add or Update a Contact and Subscribe It to a List

If you issue a contact creation request when a contact already exists (same email address), the old contact will be overwritten and any fields you don't provide will be blank on the resulting contact. To avoid this, see if a contact exists first and then issue either a create contacts request or an update contact request.

Note: Subscribing a contact to a list at the time of contact creation is a feature of version 2.3 of iContact's REST API. At the time of writing, only iContact Pro supports this version. If connecting to iContact, rather than iContact Pro, create a contact first and then subscribe it to a list using IContact.subscribeContactToList.

const contact = {
  email: '[email protected]',
  firstName: 'John',
  lastName: 'Doe',
  subscriptions: [
    {
      email: '[email protected]',
      listId: 5,
      status: 'normal'
    },
  ],
};

iContactAPI.getContacts({ email: contact.email }).then((results) => {
  if (results.total === 0) {
    return iContactAPI.addContacts([contact]);
  } else {
    return iContactAPI.updateContact(results.contacts[0].contactId, contact);
  }
}).then((results) => {
  console.log(results);
});

Reference

setTimeout

IContact.setTimeout(timeout: number): void;

Sets the request timeout in miliseconds

getTimeout

IContact.getTimeout(): number;

Returns the current request timeout in miliseconds

setAccountId

IContact.setAccountId(accountId: number): void;

Sets the iContact account ID

getAccountId

IContact.getAccountId(): number | null;

Returns the current iContact account ID

setClientFolderId

IContact.setClientFolderId(clientFolderId: number): void;

Returns the current iContact client folder ID

getClientFolderId

IContact.getClientFolderId(): number | null;

Returns the current iContact client folder ID

getContacts

IContact.getContacts(searchParameters: IContact): Promise<IContactSearchResult>;

Retrieves the contacts matching the search parameters

addContacts

IContact.addContacts(contacts: IContact[]): Promise<any>;

Adds new contacts--remember to subscribe them to a list

updateContact

IContact.updateContact(id: number, contact: IContact): Promise<any>;

Updates a contact, replacing only the fields supplied

replaceContact

IContact.replaceContact(id: number, contact: IContact): Promise<any>;

Completely replaces a contact--must include email

deleteContact

IContact.deleteContact(id: number): Promise<any>;

Deletes a contact

getLists

IContact.getLists(searchParameters?: IList): Promise<IListSearchResult>;

Retrieves the lists matching the search parameters

createLists

IContact.createLists(lists: IList[]): Promise<any>;

Adds new lists

subscribeContactToList

IContact.subscribeContactToList(contactId: number, listId: number, status?: IListStatus): Promise<any>;

Subscribes a contact to a list

Testing

Tests were written with mocha and chai.

Run them with

$ npm test

Testing will require an iContact or iContact Pro account. Provide the credentials in an .env file, following the example in .env.example.