Registry / communication / klaviyo-api-fetch

klaviyo-api-fetch

JSON →
library1.1.0jsnpmunverified

Klaviyo API client built on native fetch using hey-api codegen. Version 1.1.0 generates TypeScript types and SDK functions from Klaviyo's OpenAPI spec. It provides a lightweight, tree-shakable alternative to the official Klaviyo SDK, leveraging browser-native fetch for reduced bundle size and compatibility with modern JS environments. The package is auto-generated and released via npm with no standalone dependencies.

npm install klaviyo-api-fetch
INSTALL
IMPORT
SIG · KLAVIYO-API-FETCH
K
klaviyo-api-fetch
communicationjavascriptv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

getEvents
import { getEvents } from 'klaviyo-api-fetch'
const { getEvents } = require('klaviyo-api-fetch')
ESM-only package; CommonJS require will fail.
createOrder
import { createOrder } from 'klaviyo-api-fetch'
All API functions follow this pattern; check OpenAPI spec for exact operation names.
Client
import type { Client } from 'klaviyo-api-fetch'
import { Client } from 'klaviyo-api-fetch'
Client type is exported as a TypeScript type, not a runtime value.

Fetch events from Klaviyo API using native fetch with required auth headers and pagination fields.

import { getEvents } from 'klaviyo-api-fetch'; const apiKey = process.env.KLAVIYO_API_KEY ?? ''; const eventsRes = await getEvents({ headers: { Authorization: `Klaviyo-API-Key ${apiKey}`, revision: '2025-01-15', }, query: { 'page[cursor]': undefined, sort: '-datetime', filter: undefined, include: ['metric', 'profile'], 'fields[metric]': ['name'], 'fields[event]': ['datetime', 'timestamp', 'event_properties'], 'fields[profile]': ['email', 'first_name', 'last_name', 'phone_number'], }, }); if (eventsRes.error) { console.error(eventsRes.error); } else { console.log(eventsRes.data); }
Debug
Known issues
gotchaAll operations require the 'revision' header with a specific date string (e.g., '2025-01-15'). Missing or incorrect revision header results in a 400 error.
fix
Set 'revision' header to the appropriate API version date as documented in Klaviyo API changelog.
affects: >=1.0.0
gotchaThe package is ESM-only. Using require() will throw: ERR_REQUIRE_ESM.
fix
Use import syntax or dynamic import() instead.
affects: >=1.0.0
breakingIn version 1.0.0, the function signatures used positional arguments. Version 1.1.0 changed to a single options object parameter.
fix
Migrate from positional arguments to options object: e.g., client.getEvents({...}) instead of getEvents(headers, query, ...).
affects: <1.1.0
deprecatedThe 'fields[event]' parameter uses event_properties field which is deprecated as of Klaviyo API revision 2025-01-15.
fix
Use 'event_properties' only if necessary; prefer 'properties' field for future compatibility.
affects: >=1.1.0
Errors
Common errors & fixes
TypeError: Cannot destructure property 'getEvents' of 'klaviyo-api-fetch' as it is undefined.
Using CommonJS require() on an ESM-only package.
fix
Change const { getEvents } = require('klaviyo-api-fetch'); to import { getEvents } from 'klaviyo-api-fetch';
Error: Missing required header: revision
The 'revision' header was not provided in the request options.
fix
Add 'revision' header with a valid Klaviyo API revision date (e.g., '2025-01-15').
Response status: 400 - Invalid request
Common issue: missing or malformed query parameters, incorrect filter syntax, or wrong header values.
fix
Check the Klaviyo API documentation for correct parameter names and formats. Ensure all required fields are included.
TypeError: fetch is not defined
The runtime environment does not support native fetch (e.g., older Node.js versions).
fix
Use Node.js 18+ or install a fetch polyfill like 'node-fetch'.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
16
OpenAI (training)
1
Resources
klaviyo-api-fetch — npm install klaviyo-api-fetch · libregistry