Skip to content

ryancraigmartin/klaviyo-api-node

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Klaviyo Typescript SDK

  • SDK version: 7.2.0

  • Revision: 2023-12-15

Helpful Resources

  • If you want to suggest code changes check out our CONTRIBUTING.md document.
  • To learn about migration from our 5.x.x version check out the MIGRATION.md file.
  • Read version changes in CHANGELOG.md.

Other Klaviyo Resources

Design & Approach

This SDK is a thin wrapper around our API. See our API Reference for full documentation on API behavior.

This SDK exactly mirrors the organization and naming convention of the above language-agnostic resources, with a few namespace changes to make it fit better with Typescript

Organization

This SDK is organized into the following resources:

  • AccountsApi
  • CampaignsApi
  • CatalogsApi
  • CouponsApi
  • DataPrivacyApi
  • EventsApi
  • FlowsApi
  • ImagesApi
  • ListsApi
  • MetricsApi
  • ProfilesApi
  • SegmentsApi
  • TagsApi
  • TemplatesApi

Installation

NPM

You can install this library using npm.

npm install klaviyo-api@7.2.0

source code

Alternatively, you can also run this using this repo as source code, simply download this repo then connect to your app putting the path in your package.json or via npm link

path: add this line to your apps package.json

"klaviyo-api": "< path to downloaded source code >"

npm link:

run npm link in your local copy of this repo's directory

run npm link <"path to this repo"> first in your consuming app's directory

Sample file:

If you want to test out the repo but don't have a consuming app, you can run our sample typescript file, make whatever edits you want to sample.ts in the sample folder and use

npm run sample --pk=<YOUR PRIVATE KEY HERE>

OAuth Beta

To read about our OAuth beta for users who want to write multi-user integrations, check out this help center article

If you already are in the OAuth beta, read the documentation in the oauth-beta branch in this repo or check out the example application.

Install the beta package with the following command:

npm i klaviyo-api@beta

Usage Example

To instantiate an API wrapper using an API Key

import { ApiKeySession, ProfilesApi } from 'klaviyo-api'

const session = new ApiKeySession("< YOUR API KEY HERE >")
const profilesApi = new ProfilesApi(session)

To call the createProfile operation:

import {
  ApiKeySession,
  ProfileCreateQuery,
  ProfileEnum,
  ProfilesApi,
} from 'klaviyo-api'

const session = new ApiKeySession("< YOUR API KEY HERE >")
const profilesApi = new ProfilesApi(session)

let profile: ProfileCreateQuery = {
  data: {
  type: ProfileEnum.Profile,
  attributes: {
    email: "typescript_test_1@klaviyo-demo.com"
    }
  }
}


profilesApi.createProfile(profile).then(result => {
  console.log(result)
}).catch(error => {
  console.log(error)
});

Retry Options

Constructing an API object also has optional property RetryOptions, this acts as a light wrapper with some different defaults around the exponential-backoff library

you can override - maxRetryAttempts - timeMultiple - startingDelay

const retryOptions: RetryOptions = new RetryOptions(3, 5, 500)
const session = new ApiKeySession("< YOUR API KEY HERE >", retryOptions)

if you have used exponential backoff before you can bypass the all the settings by just setting the options with a BackoffOptions object

const retryOptions: RetryOptions = new RetryOptions()
retryOptions.options = { "BUILD YOUR OWN BackoffOptions object here" }

Organizational Helpers

There is also an optional Klaviyo import that has all the Apis and Auth, if you prefer that method for organization.

import { Klaviyo } from 'klaviyo-api'

const profilesApi = new Klaviyo.ProfilesApi(new Klaviyo.Auth.ApiKeySession("< YOUR API KEY HERE >", retryOptions))

Inspecting Errors

Failed api calls throw an AxiosError.

The two most commonly useful error items are probably - error.response.status - error.response.statusText

Here is an example of logging those errors to the console

profilesApi.createProfile(profile).then(result => {
  console.log(result.body)
}).catch(error => {
  console.log(error.response.status)
  console.log(error.response.statusText)
});

Uploading an image by file

The ImageApi exposes uploadImageFromFile()

import fs from 'fs'
import {ApiKeySession, ImageApi } from 'klaviyo-api'

const session = new ApiKeySession("< YOUR API KEY HERE >")
const imageApi = new ImagesApi(session)
imageApi.uploadImageFromFile(fs.createReadStream("./test_image.jpeg")).then(result => {
    console.log(result.body)
}).catch(error => {
  console.log(error)
}

Global Api Key

If you only connect to one Klaviyo account you may find it useful to access preconfigured objects.

Set a global key, If you were using ConfigWrapper this also sets the GlobalApiKeySettings

import { GlobalApiKeySettings } from 'klaviyo-api'

new GlobalApiKeySettings("< YOUR API KEY HERE >")

Now you can use the shortened names ProfilesApi can be referenced with Profiles

import { Profiles, GlobalApiKeySettings } from 'klaviyo-api'

new GlobalApiKeySettings("< YOUR API KEY HERE >")

Profiles.getProfiles().then(result => {
  console.log(result.body)
}).catch(error => {
  console.log(error.response.status)
  console.log(error.response.statusText)
});

Optional Parameters and JSON:API features

Here we will go over

  • Pagination
  • Page size
  • Additional Fields
  • Filtering
  • Sparse Fields
  • Sorting
  • Relationships

Quick rule

As a reminder, some optional parameters are named slightly differently from how you would make the call without the SDK docs; the reason for this is that some query parameter names have variables that make for bad JavaScript names. For example: page[cursor] becomes pageCursor. (In short: remove the non-allowed characters and append words with camelCase).

Cursor based Pagination

All the endpoints that return a list of results use cursor-based pagination.

Obtain the cursor value from the call you want to get the next page for, then pass it under the pageCursor optional parameter. The page cursor looks like WzE2NDA5OTUyMDAsICIzYzRjeXdGTndadyIsIHRydWVd.

API call:

https://a.klaviyo.com/api/profiles/?page[cursor]=WzE2NTcyMTM4NjQsICIzc042NjRyeHo0ciIsIHRydWVd

SDK call:

import { ApiKeySession, ProfilesApi } from 'klaviyo-api'

const session = new ApiKeySession("< YOUR API KEY HERE >")
const profilesApi = new ProfilesApi(session)

const profileList = await profilesApi.getProfiles({pageCursor: 'WzE2NTcyMTM4NjQsICIzc042NjRyeHo0ciIsIHRydWVd'})

You get the cursor for the next page from body.link.next. This returns the entire url of the next call, but the SDK will accept the entire link and use only the relevant cursor, so no need to do any parsing of the next link on your end

Here is an example of getting the second next and passing in the page cursor:

import { ApiKeySession, ProfilesApi } from 'klaviyo-api'

const session = new ApiKeySession("< YOUR API KEY HERE >")
const profilesApi = new ProfilesApi(session)

try {
    const profilesListFirstPage = await profilesApi.getProfiles()
    const nextPage = profilesListFirstPage.body.links.next
    const profileListSecondPage = await profilesApi.getProfiles({pageCursor: nextPage})
    console.log(profileListSecondPage.body)
} catch (e) {
    console.log(e)
}

There are more page cursors than just next: first, last, next and prev. Check the API Reference for all the paging params for a given endpoint.

Page Size

Some endpoints allow you to set the page size by using the pageSize parameter.

API call:

https://a.klaviyo.com/api/profiles/?page[size]=20

SDK call:

import { ApiKeySession, ProfilesApi } from 'klaviyo-api'

const session = new ApiKeySession("< YOUR API KEY HERE >")
const profilesApi = new ProfilesApi(session)

const profileList = await profilesApi.getProfiles({pageCursor: nextPage})

Additional Fields

Additional fields are used to populate parts of the response that would be null otherwise. For example, for the getProfile, endpoint you can pass in a request to get the predictive analytics of the profile. Using the additionalFields parameter does impact the rate limit of the endpoint in cases where the related resource is subject to a lower rate limit, so be sure to keep an eye on your usage. API call:

https://a.klaviyo.com/api/profiles/01GDDKASAP8TKDDA2GRZDSVP4H/?additional-fields[profile]=predictive_analytics

SDK call:

import { ApiKeySession, ProfilesApi } from 'klaviyo-api'

const session = new ApiKeySession("< YOUR API KEY HERE >")
const profilesApi = new ProfilesApi(session)

const profileId = '01GDDKASAP8TKDDA2GRZDSVP4H'
const profile = await profilesApi.getProfile(profileId, {additionalFieldsProfile: ['predictive_analytics']})

// If your profile has enough information for predictive analytis it will populate
console.log(profile.body.data.attributes.predictiveAnalytics)

Filtering

You can filter responses by passing a string into the optional parameter filter. Note that when filtering by a property it will be snake_case instead of camelCase, ie. metric_id

Read more about formatting your filter strings in our developer documentation

Here is an example of a filter string for results between two date times: less-than(updated,2023-04-26T00:00:00Z),greater-than(updated,2023-04-19T00:00:00Z)

Here is a code example to filter for profiles with the matching emails:

https://a.klaviyo.com/api/profiles/?filter=any(email,["henry.chan@klaviyo-demo.com","amanda.das@klaviyo-demo.com"]

SDK call:

import { ApiKeySession, ProfilesApi } from 'klaviyo-api'

const session = new ApiKeySession("< YOUR API KEY HERE >")
const profilesApi = new ProfilesApi(session)

const filter = 'any(email,["henry.chan@klaviyo-demo.com","amanda.das@klaviyo-demo.com"])'
const profileList = await profilesApi.getProfiles({filter})

Sparse Fields

If you only want a specific subset of data from a specific query you can use sparse fields to request only the specific properties. The SDK expands the optional sparse fields into their own option, where you can pass a list of the desired items to include.

To get a list of event properties the API call you would use is:

https://a.klaviyo.com/api/events/?fields[event]=event_properties

SDK call:

import { ApiKeySession, EventsApi } from 'klaviyo-api'

const session = new ApiKeySession("< YOUR API KEY HERE >")
const eventsApi = new EventsApi(session)

const eventsList = await eventsApi.getEvents({fieldsEvent: ["event_properties"]})

Sorting

Your can request the results of specific endpoints to be ordered by a given parameter. The direction of the sort can be reversed by adding a - in front of the sort key. For example datetime will be ascending while -datetime will be descending.

If you are unsure about the available sort fields, refer to the API Reference page for the endpoint you are using. For a comprehensive list that links to the documentation for each function check the Endpoints section below.

API Call to get events sorted by oldest to newest datetime:

https://a.klaviyo.com/api/events/?sort=-datetime

SDK call:

import { ApiKeySession, EventsApi } from 'klaviyo-api'

const session = new ApiKeySession("< YOUR API KEY HERE >")
const eventsApi = new EventsApi(session)

const events = await eventsApi.getEvents({sort: '-datetime'})

Includes

You can add additional information to your API response via additional fields and the includes parameter. This allows you to get information about two or more objects from a single API call. Using the includes parameter often changes the rate limit of the endpoint so be sure to take note.

API call to get profile information and the information about the lists the profile is in:

https://a.klaviyo.com/api/profiles/01GDDKASAP8TKDDA2GRZDSVP4H/?include=lists

SDK call:

import { ApiKeySession, ProfilesApi } from 'klaviyo-api'

const session = new ApiKeySession("< YOUR API KEY HERE >")
const profilesApi = new ProfilesApi(session)

const profileId = '01GDDKASAP8TKDDA2GRZDSVP4H'
const profile = await profilesApi.getProfile(profileId,{include:["lists"]})

// Profile information is accessed the same way with
console.log(profile.body.data)
// Lists related to the profile with be accessible via the included array
console.log(profile.body.included)

Note about sparse fields and relationships: you can also request only specific fields for the included object as well.

import { ApiKeySession, ProfilesApi } from 'klaviyo-api'

const session = new ApiKeySession("< YOUR API KEY HERE >")
const profilesApi = new ProfilesApi(session)

const profileId = '01GDDKASAP8TKDDA2GRZDSVP4H'
// Use the fieldsLists property to request only the list name
const profile = await profilesApi.getProfile(profileId, {fieldsList: ['name'], include: ["lists"]})

// Profile information is accessed the same way with
console.log(profile.body.data)
// Lists related to the profile with be accessible via the included array
console.log(profile.body.included)

Relationships

The Klaviyo API has a series of endpoints to expose the relationships between different Klaviyo Items. You can read more about relationships in our documentation.

Here are some use cases and their examples:

API call to get the list membership for a profile with the given profile ID:

https://a.klaviyo.com/api/profiles/01GDDKASAP8TKDDA2GRZDSVP4H/relationships/lists/

SDK call:

import { ApiKeySession, ProfilesApi } from 'klaviyo-api'

const session = new ApiKeySession("< YOUR API KEY HERE >")
const profilesApi = new ProfilesApi(session)

const profileId = '01GDDKASAP8TKDDA2GRZDSVP4H'
const profileRelationships = await profilesApi.getProfileRelationshipsLists(profileId)

For another example:

Get all campaigns associated with the given tag_id.

API call:

https://a.klaviyo.com/api/tags/9c8db7a0-5ab5-4e3c-9a37-a3224fd14382/relationships/campaigns/

SDK call:

import { ApiKeySession, TagsApi } from 'klaviyo-api'

const session = new ApiKeySession("< YOUR API KEY HERE >")
const tagsApi = new TagsApi(session)

const tagId = '9c8db7a0-5ab5-4e3c-9a37-a3224fd14382'
const relatedCampagins = tagsApi.getTagRelationshipsCampaigns(tagId)

Combining

You can use any combination of the features outlines above in conjunction with one another.

API call to get events associated with a specific metric, then return just the event properties sorted by oldest to newest datetime:

API call:

https://a.klaviyo.com/api/events/?fields[event]=event_properties&filter=equals(metric_id,"URDbLg")&sort=-datetime

SDK call:

import { ApiKeySession, EventsApi } from 'klaviyo-api'

const session = new ApiKeySession("< YOUR API KEY HERE >")
const eventsApi = new EventsApi(session)

const metricId = 'URDbLg'
const filter = `equal(metric_id,"${metricId}")`
const events = await eventsApi.getEvents({fieldsEvent: ['event_properties'], sort: '-datetime', filter})

Endpoints

AccountsApi


Get Account

AccountsApi.getAccount(id: string, options)

Get Accounts

AccountsApi.getAccounts(options)

CampaignsApi


Create Campaign

CampaignsApi.createCampaign(campaignCreateQuery: CampaignCreateQuery)

Create Campaign Clone

CampaignsApi.createCampaignClone(campaignCloneQuery: CampaignCloneQuery)

Assign Campaign Message Template

CampaignsApi.createCampaignMessageAssignTemplate(campaignMessageAssignTemplateQuery: CampaignMessageAssignTemplateQuery)

Create Campaign Recipient Estimation Job

CampaignsApi.createCampaignRecipientEstimationJob(campaignRecipientEstimationJobCreateQuery: CampaignRecipientEstimationJobCreateQuery)

Create Campaign Send Job

CampaignsApi.createCampaignSendJob(campaignSendJobCreateQuery: CampaignSendJobCreateQuery)

Delete Campaign

CampaignsApi.deleteCampaign(id: string)

Get Campaign

CampaignsApi.getCampaign(id: string, options)

Get Campaign Campaign Messages

CampaignsApi.getCampaignCampaignMessages(id: string, options)

Get Campaign Message

CampaignsApi.getCampaignMessage(id: string, options)

Get Campaign Message Campaign

CampaignsApi.getCampaignMessageCampaign(id: string, options)

Get Campaign Message Relationships Campaign

CampaignsApi.getCampaignMessageRelationshipsCampaign(id: string)

Get Campaign Message Relationships Template

CampaignsApi.getCampaignMessageRelationshipsTemplate(id: string)

Get Campaign Message Template

CampaignsApi.getCampaignMessageTemplate(id: string, options)

Get Campaign Recipient Estimation

CampaignsApi.getCampaignRecipientEstimation(id: string, options)

Get Campaign Recipient Estimation Job

CampaignsApi.getCampaignRecipientEstimationJob(id: string, options)

Get Campaign Relationships Campaign Messages

CampaignsApi.getCampaignRelationshipsCampaignMessages(id: string)

Get Campaign Relationships Tags

CampaignsApi.getCampaignRelationshipsTags(id: string)

Get Campaign Send Job

CampaignsApi.getCampaignSendJob(id: string, options)

Get Campaign Tags

CampaignsApi.getCampaignTags(id: string, options)

Get Campaigns

CampaignsApi.getCampaigns(filter: string, options)

Update Campaign

CampaignsApi.updateCampaign(id: string, campaignPartialUpdateQuery: CampaignPartialUpdateQuery)

Update Campaign Message

CampaignsApi.updateCampaignMessage(id: string, campaignMessagePartialUpdateQuery: CampaignMessagePartialUpdateQuery)

Update Campaign Send Job

CampaignsApi.updateCampaignSendJob(id: string, campaignSendJobPartialUpdateQuery: CampaignSendJobPartialUpdateQuery)

CatalogsApi


Create Back In Stock Subscription

CatalogsApi.createBackInStockSubscription(serverBISSubscriptionCreateQuery: ServerBISSubscriptionCreateQuery)

Create Catalog Category

CatalogsApi.createCatalogCategory(catalogCategoryCreateQuery: CatalogCategoryCreateQuery)

Create Catalog Category Relationships Items

CatalogsApi.createCatalogCategoryRelationshipsItems(id: string, catalogCategoryItemOp: CatalogCategoryItemOp)

Create Catalog Item

CatalogsApi.createCatalogItem(catalogItemCreateQuery: CatalogItemCreateQuery)

Create Catalog Item Relationships Categories

CatalogsApi.createCatalogItemRelationshipsCategories(id: string, catalogItemCategoryOp: CatalogItemCategoryOp)

Create Catalog Variant

CatalogsApi.createCatalogVariant(catalogVariantCreateQuery: CatalogVariantCreateQuery)

Delete Catalog Category

CatalogsApi.deleteCatalogCategory(id: string)

Delete Catalog Category Relationships Items

CatalogsApi.deleteCatalogCategoryRelationshipsItems(id: string, catalogCategoryItemOp: CatalogCategoryItemOp)

Delete Catalog Item

CatalogsApi.deleteCatalogItem(id: string)

Delete Catalog Item Relationships Categories

CatalogsApi.deleteCatalogItemRelationshipsCategories(id: string, catalogItemCategoryOp: CatalogItemCategoryOp)

Delete Catalog Variant

CatalogsApi.deleteCatalogVariant(id: string)

Get Catalog Categories

CatalogsApi.getCatalogCategories(options)

Get Catalog Category

CatalogsApi.getCatalogCategory(id: string, options)

Get Catalog Category Items

CatalogsApi.getCatalogCategoryItems(id: string, options)

Get Catalog Category Relationships Items

CatalogsApi.getCatalogCategoryRelationshipsItems(id: string, options)

Get Catalog Item

CatalogsApi.getCatalogItem(id: string, options)

Get Catalog Item Categories

CatalogsApi.getCatalogItemCategories(id: string, options)

Get Catalog Item Relationships Categories

CatalogsApi.getCatalogItemRelationshipsCategories(id: string, options)

Get Catalog Item Variants

CatalogsApi.getCatalogItemVariants(id: string, options)

Get Catalog Items

CatalogsApi.getCatalogItems(options)

Get Catalog Variant

CatalogsApi.getCatalogVariant(id: string, options)

Get Catalog Variants

CatalogsApi.getCatalogVariants(options)

Get Create Categories Job

CatalogsApi.getCreateCategoriesJob(jobId: string, options)

Get Create Categories Jobs

CatalogsApi.getCreateCategoriesJobs(options)

Get Create Items Job

CatalogsApi.getCreateItemsJob(jobId: string, options)

Get Create Items Jobs

CatalogsApi.getCreateItemsJobs(options)

Get Create Variants Job

CatalogsApi.getCreateVariantsJob(jobId: string, options)

Get Create Variants Jobs

CatalogsApi.getCreateVariantsJobs(options)

Get Delete Categories Job

CatalogsApi.getDeleteCategoriesJob(jobId: string, options)

Get Delete Categories Jobs

CatalogsApi.getDeleteCategoriesJobs(options)

Get Delete Items Job

CatalogsApi.getDeleteItemsJob(jobId: string, options)

Get Delete Items Jobs

CatalogsApi.getDeleteItemsJobs(options)

Get Delete Variants Job

CatalogsApi.getDeleteVariantsJob(jobId: string, options)

Get Delete Variants Jobs

CatalogsApi.getDeleteVariantsJobs(options)

Get Update Categories Job

CatalogsApi.getUpdateCategoriesJob(jobId: string, options)

Get Update Categories Jobs

CatalogsApi.getUpdateCategoriesJobs(options)

Get Update Items Job

CatalogsApi.getUpdateItemsJob(jobId: string, options)

Get Update Items Jobs

CatalogsApi.getUpdateItemsJobs(options)

Get Update Variants Job

CatalogsApi.getUpdateVariantsJob(jobId: string, options)

Get Update Variants Jobs

CatalogsApi.getUpdateVariantsJobs(options)

Spawn Create Categories Job

CatalogsApi.spawnCreateCategoriesJob(catalogCategoryCreateJobCreateQuery: CatalogCategoryCreateJobCreateQuery)

Spawn Create Items Job

CatalogsApi.spawnCreateItemsJob(catalogItemCreateJobCreateQuery: CatalogItemCreateJobCreateQuery)

Spawn Create Variants Job

CatalogsApi.spawnCreateVariantsJob(catalogVariantCreateJobCreateQuery: CatalogVariantCreateJobCreateQuery)

Spawn Delete Categories Job

CatalogsApi.spawnDeleteCategoriesJob(catalogCategoryDeleteJobCreateQuery: CatalogCategoryDeleteJobCreateQuery)

Spawn Delete Items Job

CatalogsApi.spawnDeleteItemsJob(catalogItemDeleteJobCreateQuery: CatalogItemDeleteJobCreateQuery)

Spawn Delete Variants Job

CatalogsApi.spawnDeleteVariantsJob(catalogVariantDeleteJobCreateQuery: CatalogVariantDeleteJobCreateQuery)

Spawn Update Categories Job

CatalogsApi.spawnUpdateCategoriesJob(catalogCategoryUpdateJobCreateQuery: CatalogCategoryUpdateJobCreateQuery)

Spawn Update Items Job

CatalogsApi.spawnUpdateItemsJob(catalogItemUpdateJobCreateQuery: CatalogItemUpdateJobCreateQuery)

Spawn Update Variants Job

CatalogsApi.spawnUpdateVariantsJob(catalogVariantUpdateJobCreateQuery: CatalogVariantUpdateJobCreateQuery)

Update Catalog Category

CatalogsApi.updateCatalogCategory(id: string, catalogCategoryUpdateQuery: CatalogCategoryUpdateQuery)

Update Catalog Category Relationships Items

CatalogsApi.updateCatalogCategoryRelationshipsItems(id: string, catalogCategoryItemOp: CatalogCategoryItemOp)

Update Catalog Item

CatalogsApi.updateCatalogItem(id: string, catalogItemUpdateQuery: CatalogItemUpdateQuery)

Update Catalog Item Relationships Categories

CatalogsApi.updateCatalogItemRelationshipsCategories(id: string, catalogItemCategoryOp: CatalogItemCategoryOp)

Update Catalog Variant

CatalogsApi.updateCatalogVariant(id: string, catalogVariantUpdateQuery: CatalogVariantUpdateQuery)

CouponsApi


Create Coupon

CouponsApi.createCoupon(couponCreateQuery: CouponCreateQuery)

Create Coupon Code

CouponsApi.createCouponCode(couponCodeCreateQuery: CouponCodeCreateQuery)

Delete Coupon

CouponsApi.deleteCoupon(id: string)

Delete Coupon Code

CouponsApi.deleteCouponCode(id: string)

Get Coupon

CouponsApi.getCoupon(id: string, options)

Get Coupon Code

CouponsApi.getCouponCode(id: string, options)

Get Coupon Code Bulk Create Job

CouponsApi.getCouponCodeBulkCreateJob(jobId: string, options)

Get Coupon Code Bulk Create Jobs

CouponsApi.getCouponCodeBulkCreateJobs(options)

Get Coupon Code Relationships Coupon

CouponsApi.getCouponCodeRelationshipsCoupon(id: string, options)

Get Coupon Codes

CouponsApi.getCouponCodes(options)

Get Coupon Codes For Coupon

CouponsApi.getCouponCodesForCoupon(id: string, options)

Get Coupon For Coupon Code

CouponsApi.getCouponForCouponCode(id: string, options)

Get Coupon Relationships Coupon Codes

CouponsApi.getCouponRelationshipsCouponCodes(id: string)

Get Coupons

CouponsApi.getCoupons(options)

Spawn Coupon Code Bulk Create Job

CouponsApi.spawnCouponCodeBulkCreateJob(couponCodeCreateJobCreateQuery: CouponCodeCreateJobCreateQuery)

Update Coupon

CouponsApi.updateCoupon(id: string, couponUpdateQuery: CouponUpdateQuery)

Update Coupon Code

CouponsApi.updateCouponCode(id: string, couponCodeUpdateQuery: CouponCodeUpdateQuery)

DataPrivacyApi


Request Profile Deletion

DataPrivacyApi.requestProfileDeletion(dataPrivacyCreateDeletionJobQuery: DataPrivacyCreateDeletionJobQuery)

EventsApi


Create Event

EventsApi.createEvent(eventCreateQueryV2: EventCreateQueryV2)

Get Event

EventsApi.getEvent(id: string, options)

Get Event Metric

EventsApi.getEventMetric(id: string, options)

Get Event Profile

EventsApi.getEventProfile(id: string, options)

Get Event Relationships Metric

EventsApi.getEventRelationshipsMetric(id: string)

Get Event Relationships Profile

EventsApi.getEventRelationshipsProfile(id: string)

Get Events

EventsApi.getEvents(options)

FlowsApi


Get Flow

FlowsApi.getFlow(id: string, options)

Get Flow Action

FlowsApi.getFlowAction(id: string, options)

Get Flow For Flow Action

FlowsApi.getFlowActionFlow(id: string, options)

Get Flow Action Messages

FlowsApi.getFlowActionMessages(id: string, options)

Get Flow Action Relationships Flow

FlowsApi.getFlowActionRelationshipsFlow(id: string)

Get Flow Action Relationships Messages

FlowsApi.getFlowActionRelationshipsMessages(id: string, options)

Get Flow Flow Actions

FlowsApi.getFlowFlowActions(id: string, options)

Get Flow Message

FlowsApi.getFlowMessage(id: string, options)

Get Flow Action For Message

FlowsApi.getFlowMessageAction(id: string, options)

Get Flow Message Relationships Action

FlowsApi.getFlowMessageRelationshipsAction(id: string)

Get Flow Message Relationships Template

FlowsApi.getFlowMessageRelationshipsTemplate(id: string)

Get Flow Message Template

FlowsApi.getFlowMessageTemplate(id: string, options)

Get Flow Relationships Flow Actions

FlowsApi.getFlowRelationshipsFlowActions(id: string, options)

Get Flow Relationships Tags

FlowsApi.getFlowRelationshipsTags(id: string)

Get Flow Tags

FlowsApi.getFlowTags(id: string, options)

Get Flows

FlowsApi.getFlows(options)

Update Flow Status

FlowsApi.updateFlow(id: string, flowUpdateQuery: FlowUpdateQuery)

ImagesApi


Get Image

ImagesApi.getImage(id: string, options)

Get Images

ImagesApi.getImages(options)

Update Image

ImagesApi.updateImage(id: string, imagePartialUpdateQuery: ImagePartialUpdateQuery)

Upload Image From File

ImagesApi.uploadImageFromFile(file: RequestFile, )

Upload Image From URL

ImagesApi.uploadImageFromUrl(imageCreateQuery: ImageCreateQuery)

ListsApi


Create List

ListsApi.createList(listCreateQuery: ListCreateQuery)

Add Profile To List

ListsApi.createListRelationships(id: string, listMembersAddQuery: ListMembersAddQuery)

Delete List

ListsApi.deleteList(id: string)

Remove Profile From List

ListsApi.deleteListRelationships(id: string, listMembersDeleteQuery: ListMembersDeleteQuery)

Get List

ListsApi.getList(id: string, options)

Get List Profiles

ListsApi.getListProfiles(id: string, options)

Get List Relationships Profiles

ListsApi.getListRelationshipsProfiles(id: string, options)

Get List Relationships Tags

ListsApi.getListRelationshipsTags(id: string)

Get List Tags

ListsApi.getListTags(id: string, options)

Get Lists

ListsApi.getLists(options)

Update List

ListsApi.updateList(id: string, listPartialUpdateQuery: ListPartialUpdateQuery)

MetricsApi


Get Metric

MetricsApi.getMetric(id: string, options)

Get Metrics

MetricsApi.getMetrics(options)

Query Metric Aggregates

MetricsApi.queryMetricAggregates(metricAggregateQuery: MetricAggregateQuery)

ProfilesApi


Create Profile

ProfilesApi.createProfile(profileCreateQuery: ProfileCreateQuery)

Create or Update Push Token

ProfilesApi.createPushToken(pushTokenCreateQuery: PushTokenCreateQuery)

Get Bulk Profile Import Job

ProfilesApi.getBulkProfileImportJob(jobId: string, options)

Get Bulk Profile Import Job Import Errors

ProfilesApi.getBulkProfileImportJobImportErrors(id: string, options)

Get Bulk Profile Import Job Lists

ProfilesApi.getBulkProfileImportJobLists(id: string, options)

Get Bulk Profile Import Job Profiles

ProfilesApi.getBulkProfileImportJobProfiles(id: string, options)

Get Bulk Profile Import Job Relationships Lists

ProfilesApi.getBulkProfileImportJobRelationshipsLists(id: string)

Get Bulk Profile Import Job Relationships Profiles

ProfilesApi.getBulkProfileImportJobRelationshipsProfiles(id: string, options)

Get Bulk Profile Import Jobs

ProfilesApi.getBulkProfileImportJobs(options)

Get Profile

ProfilesApi.getProfile(id: string, options)

Get Profile Lists

ProfilesApi.getProfileLists(id: string, options)

Get Profile Relationships Lists

ProfilesApi.getProfileRelationshipsLists(id: string)

Get Profile Relationships Segments

ProfilesApi.getProfileRelationshipsSegments(id: string)

Get Profile Segments

ProfilesApi.getProfileSegments(id: string, options)

Get Profiles

ProfilesApi.getProfiles(options)

Merge Profiles

ProfilesApi.mergeProfiles(profileMergeQuery: ProfileMergeQuery)

Spawn Bulk Profile Import Job

ProfilesApi.spawnBulkProfileImportJob(profileImportJobCreateQuery: ProfileImportJobCreateQuery)

Subscribe Profiles

ProfilesApi.subscribeProfiles(subscriptionCreateJobCreateQuery: SubscriptionCreateJobCreateQuery)

Suppress Profiles

ProfilesApi.suppressProfiles(suppressionCreateJobCreateQuery: SuppressionCreateJobCreateQuery)

Unsubscribe Profiles

ProfilesApi.unsubscribeProfiles(subscriptionDeleteJobCreateQuery: SubscriptionDeleteJobCreateQuery)

Unsuppress Profiles

ProfilesApi.unsuppressProfiles(suppressionDeleteJobCreateQuery: SuppressionDeleteJobCreateQuery)

Update Profile

ProfilesApi.updateProfile(id: string, profilePartialUpdateQuery: ProfilePartialUpdateQuery)

SegmentsApi


Get Segment

SegmentsApi.getSegment(id: string, options)

Get Segment Profiles

SegmentsApi.getSegmentProfiles(id: string, options)

Get Segment Relationships Profiles

SegmentsApi.getSegmentRelationshipsProfiles(id: string, options)

Get Segment Relationships Tags

SegmentsApi.getSegmentRelationshipsTags(id: string)

Get Segment Tags

SegmentsApi.getSegmentTags(id: string, options)

Get Segments

SegmentsApi.getSegments(options)

Update Segment

SegmentsApi.updateSegment(id: string, segmentPartialUpdateQuery: SegmentPartialUpdateQuery)

TagsApi


Create Tag

TagsApi.createTag(tagCreateQuery: TagCreateQuery)

Create Tag Group

TagsApi.createTagGroup(tagGroupCreateQuery: TagGroupCreateQuery)

Create Tag Relationships Campaigns

TagsApi.createTagRelationshipsCampaigns(id: string, tagCampaignOp: TagCampaignOp)

Create Tag Relationships Flows

TagsApi.createTagRelationshipsFlows(id: string, tagFlowOp: TagFlowOp)

Create Tag Relationships Lists

TagsApi.createTagRelationshipsLists(id: string, tagListOp: TagListOp)

Create Tag Relationships Segments

TagsApi.createTagRelationshipsSegments(id: string, tagSegmentOp: TagSegmentOp)

Delete Tag

TagsApi.deleteTag(id: string)

Delete Tag Group

TagsApi.deleteTagGroup(id: string)

Delete Tag Relationships Campaigns

TagsApi.deleteTagRelationshipsCampaigns(id: string, tagCampaignOp: TagCampaignOp)

Delete Tag Relationships Flows

TagsApi.deleteTagRelationshipsFlows(id: string, tagFlowOp: TagFlowOp)

Delete Tag Relationships Lists

TagsApi.deleteTagRelationshipsLists(id: string, tagListOp: TagListOp)

Delete Tag Relationships Segments

TagsApi.deleteTagRelationshipsSegments(id: string, tagSegmentOp: TagSegmentOp)

Get Tag

TagsApi.getTag(id: string, options)

Get Tag Group

TagsApi.getTagGroup(id: string, options)

Get Tag Group Relationships Tags

TagsApi.getTagGroupRelationshipsTags(id: string)

Get Tag Group Tags

TagsApi.getTagGroupTags(id: string, options)

Get Tag Groups

TagsApi.getTagGroups(options)

Get Tag Relationships Campaigns

TagsApi.getTagRelationshipsCampaigns(id: string)

Get Tag Relationships Flows

TagsApi.getTagRelationshipsFlows(id: string)

Get Tag Relationships Lists

TagsApi.getTagRelationshipsLists(id: string)

Get Tag Relationships Segments

TagsApi.getTagRelationshipsSegments(id: string)

Get Tag Relationships Tag Group

TagsApi.getTagRelationshipsTagGroup(id: string)

Get Tag Tag Group

TagsApi.getTagTagGroup(id: string, options)

Get Tags

TagsApi.getTags(options)

Update Tag

TagsApi.updateTag(id: string, tagUpdateQuery: TagUpdateQuery)

Update Tag Group

TagsApi.updateTagGroup(id: string, tagGroupUpdateQuery: TagGroupUpdateQuery)

TemplatesApi


Create Template

TemplatesApi.createTemplate(templateCreateQuery: TemplateCreateQuery)

Create Template Clone

TemplatesApi.createTemplateClone(templateCloneQuery: TemplateCloneQuery)

Create Template Render

TemplatesApi.createTemplateRender(templateRenderQuery: TemplateRenderQuery)

Delete Template

TemplatesApi.deleteTemplate(id: string)

Get Template

TemplatesApi.getTemplate(id: string, options)

Get Templates

TemplatesApi.getTemplates(options)

Update Template

TemplatesApi.updateTemplate(id: string, templateUpdateQuery: TemplateUpdateQuery)

Appendix

Refresher on catching exceptions:

try {
    await YOUR_CALL_HERE
} catch (e) {
    console.log(e)
}

Namespace

In the interest of making the SDK follow conventions, we made the following namespace changes relative to the language agnostic resources up top.

  1. dashes - are removed in favor of camelCase
  2. all other non-alphanumeric symbols, including spaces, are removed.

For example:

  • get-campaigns becomes getCampaigns
  • Data Privacy become DataPrivacy

Parameters & Arguments

The parameters follow the same naming conventions as the resource groups and operations.

We stick to the following convention for parameters/arguments

  1. All query and path params that are tagged as required in the docs are passed as positional args.
  2. There is no need to pass in your private apiKey for any operations, as it is defined upon api instantiation; public key is still required where its used.

About

Node sdk for the Klaviyo API

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%