Skip to content

Latest commit

 

History

History
70 lines (46 loc) · 1.71 KB

README.md

File metadata and controls

70 lines (46 loc) · 1.71 KB

Klaviyo API client for Node.js and browser

This is a Klaviyo API client for Node.js and browser written in Typescript.

Installation

npm i klaviyo-client

or

yarn add klaviyo-client

Simple Example

As demonstrated by this example, you can:

  • identify profiles
  • track their events
  • get profiles from list and segments
  • get complete profile data
  • get a list of profile events

And also you can define strongly-typed profile properties.

import { KlaviyoClient } from 'klaviyo-client';

...

type CustomKlaviyoProfileProperties = {
  status: 'happy' | 'excited';
};

...

await klaviyo.identify<CustomKlaviyoProfileProperties>({ $email: '[email protected]', status: 'happy' });

await klaviyo.track<CustomKlaviyoProfileProperties>(
    'smiled',
    { $email: '[email protected]', status: 'excited' },
    { reason: 'because of you' },
);

const persons = await klaviyo.getGroupProfiles('XV77mQ');
console.log(`There are ${persons.length} happy persons.`);

for (const p of persons) {
    const person = await klaviyo.getProfile<CustomKlaviyoProfileProperties>(p.id);
    console.log(`${person.$first_name} is ${person.status}.`);

    const events = await klaviyo.getProfileEvents(p.id);
    console.log(`${person.$first_name} has smiled ${events.length} times.`);
}

Configuration

You can get API key and token in your Klaviyo account here.

Token is also known as Site ID or public API key.

Please read Klaviyo API documentation.

Need Help or Feature?

Drop me an email to Mikhail Monchak