Customer.io Node.js Client

4.3.0 · active · verified Sun Apr 19

The customerio-node package provides an official Node.js client for interacting with the Customer.io Journeys REST API. It allows developers to perform core actions such as identifying customers, tracking events, deleting profiles, and sending transactional emails, SMS, push, and Inbox messages. The current stable version is 4.3.0, with regular patch and minor releases addressing bug fixes and adding new transactional messaging capabilities. Major versions, like v4.0.0, introduce breaking changes, primarily for API consistency. While this client is robust for the Journeys API, for new integrations, Customer.io generally recommends using their Data Pipelines JavaScript client (`@customerio/cdp-analytics-js`), which provides a unified interface across various data sources. This library is designed for Node.js environments and warns against use in alternative runtimes due to potential API differences.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Customer.io `TrackClient` and identify a customer with their basic attributes, using environment variables for credentials.

import { TrackClient, RegionUS } from 'customerio-node';

const siteId = process.env.CUSTOMERIO_SITE_ID ?? '';
const apiKey = process.env.CUSTOMERIO_API_KEY ?? '';

if (!siteId || !apiKey) {
  console.error('CUSTOMERIO_SITE_ID and CUSTOMERIO_API_KEY environment variables are required.');
  process.exit(1);
}

const cio = new TrackClient(siteId, apiKey, { region: RegionUS });

async function identifyCustomer() {
  try {
    await cio.identify('customer_123', {
      email: 'customer@example.com',
      created_at: Math.floor(Date.now() / 1000),
      first_name: 'Jane',
      last_name: 'Doe',
      plan: 'premium'
    });
    console.log('Customer identified successfully.');
  } catch (error) {
    console.error('Failed to identify customer:', error);
  }
}

identifyCustomer();

view raw JSON →