klaviyo-node

raw JSON →
1.0.8 verified Sat May 09 auth: no javascript maintenance

Unofficial Node.js client for Klaviyo's HTTP API (v1.0.8, last updated 2020). Designed for server-side tracking of customer events and profile identification. Uses public token for track/identify and private API key for metrics/lists. No TypeScript types; requires Node 6+. Minimal abstraction over Klaviyo's REST API. Not affiliated with Klaviyo.

error TypeError: Klaviyo is not a constructor
cause Using named import instead of default import (ESM) or wrong require destructuring (CJS).
fix
Use: const Klaviyo = require('klaviyo-node'); // CJS or import Klaviyo from 'klaviyo-node'; // ESM
error Error: You must pass a public API key
cause Constructing Klaviyo instance without arguments or with undefined token.
fix
Pass your Klaviyo public token as first argument: new Klaviyo('pk_...');
error Request failed with status 403
cause Using private API key for track/identify endpoints which require public token.
fix
Use the public API key (starts with 'pk_') for client instantiation when calling track or identify.
gotcha The 'track' method requires a public token; using a private API key will cause authentication failures.
fix Ensure you use your Klaviyo Public API Key (found in Klaviyo > Settings > API Keys) for track/identify calls.
deprecated The package uses deprecated Klaviyo v1 API endpoints which may be removed in the future.
fix Migrate to the official Klaviyo SDK (klaviyo) which uses v2 API.
breaking No breaking changes documented; package is stable but unmaintained.
fix No fix needed; but consider switching to official SDK.
npm install klaviyo-node
yarn add klaviyo-node
pnpm add klaviyo-node

Initializes client with public token from env, tracks a purchase event with profile properties, and identifies a profile with custom properties.

const Klaviyo = require('klaviyo-node');
const client = new Klaviyo(process.env.KLAVIYO_PUBLIC_TOKEN ?? '');

// Track an event
client.track(
  'Purchased Item',
  { $email: 'customer@example.com' },
  { item: 'Shoes', price: 59.99 },
  { $first_name: 'Jane', $last_name: 'Doe' }
);

// Identify a profile
client.identify(
  { $email: 'customer@example.com' },
  { Plan: 'Premium', $city: 'New York' }
);

console.log('Events tracked successfully');