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.
Common errors
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.
Warnings
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.
Install
npm install klaviyo-node yarn add klaviyo-node pnpm add klaviyo-node Imports
- default wrong
const { Klaviyo } = require('klaviyo-node');correctimport Klaviyo from 'klaviyo-node'; - Klaviyo (constructor) wrong
new Klaviyo();correctconst client = new Klaviyo('PUBLIC_TOKEN'); - track wrong
client.track({ event: 'Event', email: '...' });correctclient.track('Event Name', 'email@example.com', { property: 'value' }); - identify wrong
client.identify({ email: '...', properties: {...} });correctclient.identify('email@example.com', { '$first_name': 'John' });
Quickstart
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');