/**
* Klaviyo API
* The Klaviyo REST API. Please visit https://developers.klaviyo.com for more details.
*
* Contact: developers@klaviyo.com
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
const axios = require('axios');
import {AxiosRequestConfig, AxiosResponse} from "axios";
import FormData from 'form-data'
/* tslint:disable:no-unused-locals */
import { CustomMetricCreateQuery } from '../model/customMetricCreateQuery';
import { CustomMetricPartialUpdateQuery } from '../model/customMetricPartialUpdateQuery';
import { GetAccounts4XXResponse } from '../model/getAccounts4XXResponse';
import { GetCustomMetricMetricsRelationshipsResponseCollection } from '../model/getCustomMetricMetricsRelationshipsResponseCollection';
import { GetCustomMetricResponse } from '../model/getCustomMetricResponse';
import { GetCustomMetricResponseCollectionCompoundDocument } from '../model/getCustomMetricResponseCollectionCompoundDocument';
import { GetCustomMetricResponseCompoundDocument } from '../model/getCustomMetricResponseCompoundDocument';
import { GetFlowResponseCollection } from '../model/getFlowResponseCollection';
import { GetMappedMetricCustomMetricRelationshipResponse } from '../model/getMappedMetricCustomMetricRelationshipResponse';
import { GetMappedMetricMetricRelationshipResponse } from '../model/getMappedMetricMetricRelationshipResponse';
import { GetMappedMetricResponseCollectionCompoundDocument } from '../model/getMappedMetricResponseCollectionCompoundDocument';
import { GetMappedMetricResponseCompoundDocument } from '../model/getMappedMetricResponseCompoundDocument';
import { GetMetricFlowTriggersRelationshipsResponseCollection } from '../model/getMetricFlowTriggersRelationshipsResponseCollection';
import { GetMetricPropertiesRelationshipsResponseCollection } from '../model/getMetricPropertiesRelationshipsResponseCollection';
import { GetMetricPropertyMetricRelationshipResponse } from '../model/getMetricPropertyMetricRelationshipResponse';
import { GetMetricPropertyResponseCollection } from '../model/getMetricPropertyResponseCollection';
import { GetMetricPropertyResponseCompoundDocument } from '../model/getMetricPropertyResponseCompoundDocument';
import { GetMetricResponse } from '../model/getMetricResponse';
import { GetMetricResponseCollection } from '../model/getMetricResponseCollection';
import { GetMetricResponseCollectionCompoundDocument } from '../model/getMetricResponseCollectionCompoundDocument';
import { GetMetricResponseCompoundDocument } from '../model/getMetricResponseCompoundDocument';
import { MappedMetricPartialUpdateQuery } from '../model/mappedMetricPartialUpdateQuery';
import { MetricAggregateQuery } from '../model/metricAggregateQuery';
import { PatchCustomMetricResponse } from '../model/patchCustomMetricResponse';
import { PatchMappedMetricResponse } from '../model/patchMappedMetricResponse';
import { PostCustomMetricResponse } from '../model/postCustomMetricResponse';
import { PostMetricAggregateResponse } from '../model/postMetricAggregateResponse';
import { ObjectSerializer } from '../model/models';
import {RequestFile, queryParamPreProcessor, RetryWithExponentialBackoff, Session} from './apis';
let defaultBasePath = 'https://a.klaviyo.com';
// ===============================================
// This file is autogenerated - Please do not edit
// ===============================================
export class MetricsApi {
session: Session
protected _basePath = defaultBasePath;
protected _defaultHeaders : any = {};
protected _useQuerystring : boolean = false;
constructor(session: Session){
this.session = session
}
set useQuerystring(value: boolean) {
this._useQuerystring = value;
}
set basePath(basePath: string) {
this._basePath = basePath;
}
set defaultHeaders(defaultHeaders: any) {
this._defaultHeaders = defaultHeaders;
}
get defaultHeaders() {
return this._defaultHeaders;
}
get basePath() {
return this._basePath;
}
/**
* Create a new custom metric. Custom metric objects must include a `name` and `definition`.
*Rate limits*:
Burst: `1/s`
Steady: `15/m`
Daily: `15/d` **Scopes:** `metrics:write`
* @summary Create Custom Metric
* @param customMetricCreateQuery Create a custom metric.
*/
public async createCustomMetric (customMetricCreateQuery: CustomMetricCreateQuery, ): Promise<{ response: AxiosResponse; body: PostCustomMetricResponse; }> {
const localVarPath = this.basePath + '/api/custom-metrics';
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
// verify required parameter 'customMetricCreateQuery' is not null or undefined
if (customMetricCreateQuery === null || customMetricCreateQuery === undefined) {
throw new Error('Required parameter customMetricCreateQuery was null or undefined when calling createCustomMetric.');
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'POST',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
data: ObjectSerializer.serialize(customMetricCreateQuery, "CustomMetricCreateQuery")
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: PostCustomMetricResponse; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "PostCustomMetricResponse");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Delete a custom metric with the given custom metric ID.
*Rate limits*:
Burst: `3/s`
Steady: `60/m` **Scopes:** `metrics:write`
* @summary Delete Custom Metric
* @param id The ID of the custom metric
*/
public async deleteCustomMetric (id: string, ): Promise<{ response: AxiosResponse; body?: any; }> {
const localVarPath = this.basePath + '/api/custom-metrics/{id}'
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling deleteCustomMetric.');
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'DELETE',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body?: any; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Get a custom metric with the given custom metric ID.
*Rate limits*:
Burst: `3/s`
Steady: `60/m` **Scopes:** `metrics:read`
* @summary Get Custom Metric
* @param id The ID of the custom metric
* @param fieldsCustomMetric For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets* @param fieldsMetric For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets* @param include For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#relationships
*/
public async getCustomMetric (id: string, options: { fieldsCustomMetric?: Array<'created' | 'definition' | 'definition.aggregation_method' | 'definition.metric_groups' | 'name' | 'updated'>, fieldsMetric?: Array<'created' | 'integration' | 'name' | 'updated'>, include?: Array<'metrics'>, } = {}): Promise<{ response: AxiosResponse; body: GetCustomMetricResponseCompoundDocument; }> {
const localVarPath = this.basePath + '/api/custom-metrics/{id}'
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling getCustomMetric.');
}
if (options.fieldsCustomMetric !== undefined) {
localVarQueryParameters['fields[custom-metric]'] = ObjectSerializer.serialize(options.fieldsCustomMetric, "Array<'created' | 'definition' | 'definition.aggregation_method' | 'definition.metric_groups' | 'name' | 'updated'>");
}
if (options.fieldsMetric !== undefined) {
localVarQueryParameters['fields[metric]'] = ObjectSerializer.serialize(options.fieldsMetric, "Array<'created' | 'integration' | 'name' | 'updated'>");
}
if (options.include !== undefined) {
localVarQueryParameters['include'] = ObjectSerializer.serialize(options.include, "Array<'metrics'>");
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'GET',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: GetCustomMetricResponseCompoundDocument; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetCustomMetricResponseCompoundDocument");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Get the custom metric for the given mapped metric ID (if applicable).
*Rate limits*:
Burst: `3/s`
Steady: `60/m` **Scopes:** `metrics:read`
* @summary Get Custom Metric for Mapped Metric
* @param id The type of mapping.
* @param fieldsCustomMetric For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets
*/
public async getCustomMetricForMappedMetric (id: 'added_to_cart' | 'cancelled_sales' | 'ordered_product' | 'refunded_sales' | 'revenue' | 'started_checkout' | 'viewed_product', options: { fieldsCustomMetric?: Array<'created' | 'definition' | 'definition.aggregation_method' | 'definition.metric_groups' | 'name' | 'updated'>, } = {}): Promise<{ response: AxiosResponse; body: GetCustomMetricResponse; }> {
const localVarPath = this.basePath + '/api/mapped-metrics/{id}/custom-metric'
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling getCustomMetricForMappedMetric.');
}
if (options.fieldsCustomMetric !== undefined) {
localVarQueryParameters['fields[custom-metric]'] = ObjectSerializer.serialize(options.fieldsCustomMetric, "Array<'created' | 'definition' | 'definition.aggregation_method' | 'definition.metric_groups' | 'name' | 'updated'>");
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'GET',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: GetCustomMetricResponse; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetCustomMetricResponse");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Get the ID of the custom metric for the given mapped metric.
*Rate limits*:
Burst: `3/s`
Steady: `60/m` **Scopes:** `metrics:read`
* @summary Get Custom Metric ID for Mapped Metric
* @param id The type of mapping.
*/
public async getCustomMetricIdForMappedMetric (id: 'added_to_cart' | 'cancelled_sales' | 'ordered_product' | 'refunded_sales' | 'revenue' | 'started_checkout' | 'viewed_product', ): Promise<{ response: AxiosResponse; body: GetMappedMetricCustomMetricRelationshipResponse; }> {
const localVarPath = this.basePath + '/api/mapped-metrics/{id}/relationships/custom-metric'
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling getCustomMetricIdForMappedMetric.');
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'GET',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: GetMappedMetricCustomMetricRelationshipResponse; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetMappedMetricCustomMetricRelationshipResponse");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Get all custom metrics in an account.
*Rate limits*:
Burst: `3/s`
Steady: `60/m` **Scopes:** `metrics:read`
* @summary Get Custom Metrics
* @param fieldsCustomMetric For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets* @param fieldsMetric For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets* @param include For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#relationships
*/
public async getCustomMetrics (options: { fieldsCustomMetric?: Array<'created' | 'definition' | 'definition.aggregation_method' | 'definition.metric_groups' | 'name' | 'updated'>, fieldsMetric?: Array<'created' | 'integration' | 'name' | 'updated'>, include?: Array<'metrics'>, } = {}): Promise<{ response: AxiosResponse; body: GetCustomMetricResponseCollectionCompoundDocument; }> {
const localVarPath = this.basePath + '/api/custom-metrics';
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
if (options.fieldsCustomMetric !== undefined) {
localVarQueryParameters['fields[custom-metric]'] = ObjectSerializer.serialize(options.fieldsCustomMetric, "Array<'created' | 'definition' | 'definition.aggregation_method' | 'definition.metric_groups' | 'name' | 'updated'>");
}
if (options.fieldsMetric !== undefined) {
localVarQueryParameters['fields[metric]'] = ObjectSerializer.serialize(options.fieldsMetric, "Array<'created' | 'integration' | 'name' | 'updated'>");
}
if (options.include !== undefined) {
localVarQueryParameters['include'] = ObjectSerializer.serialize(options.include, "Array<'metrics'>");
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'GET',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: GetCustomMetricResponseCollectionCompoundDocument; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetCustomMetricResponseCollectionCompoundDocument");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Get all flows where the given metric is being used as the trigger.
*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `flows:read` `metrics:read`
* @summary Get Flows Triggered by Metric
* @param id
* @param fieldsFlow For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets
*/
public async getFlowsTriggeredByMetric (id: string, options: { fieldsFlow?: Array<'archived' | 'created' | 'name' | 'status' | 'trigger_type' | 'updated'>, } = {}): Promise<{ response: AxiosResponse; body: GetFlowResponseCollection; }> {
const localVarPath = this.basePath + '/api/metrics/{id}/flow-triggers'
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling getFlowsTriggeredByMetric.');
}
if (options.fieldsFlow !== undefined) {
localVarQueryParameters['fields[flow]'] = ObjectSerializer.serialize(options.fieldsFlow, "Array<'archived' | 'created' | 'name' | 'status' | 'trigger_type' | 'updated'>");
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'GET',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: GetFlowResponseCollection; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetFlowResponseCollection");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Get the IDs of all flows where the given metric is being used as the trigger.
*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `flows:read` `metrics:read`
* @summary Get IDs for Flows Triggered by Metric
* @param id
*/
public async getIdsForFlowsTriggeredByMetric (id: string, ): Promise<{ response: AxiosResponse; body: GetMetricFlowTriggersRelationshipsResponseCollection; }> {
const localVarPath = this.basePath + '/api/metrics/{id}/relationships/flow-triggers'
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling getIdsForFlowsTriggeredByMetric.');
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'GET',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: GetMetricFlowTriggersRelationshipsResponseCollection; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetMetricFlowTriggersRelationshipsResponseCollection");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Get the mapped metric with the given ID.
*Rate limits*:
Burst: `3/s`
Steady: `60/m` **Scopes:** `metrics:read`
* @summary Get Mapped Metric
* @param id The type of mapping.
* @param fieldsCustomMetric For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets* @param fieldsMappedMetric For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets* @param fieldsMetric For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets* @param include For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#relationships
*/
public async getMappedMetric (id: 'added_to_cart' | 'cancelled_sales' | 'ordered_product' | 'refunded_sales' | 'revenue' | 'started_checkout' | 'viewed_product', options: { fieldsCustomMetric?: Array<'created' | 'definition' | 'definition.aggregation_method' | 'definition.metric_groups' | 'name' | 'updated'>, fieldsMappedMetric?: Array<'updated'>, fieldsMetric?: Array<'created' | 'integration' | 'name' | 'updated'>, include?: Array<'custom-metric' | 'metric'>, } = {}): Promise<{ response: AxiosResponse; body: GetMappedMetricResponseCompoundDocument; }> {
const localVarPath = this.basePath + '/api/mapped-metrics/{id}'
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling getMappedMetric.');
}
if (options.fieldsCustomMetric !== undefined) {
localVarQueryParameters['fields[custom-metric]'] = ObjectSerializer.serialize(options.fieldsCustomMetric, "Array<'created' | 'definition' | 'definition.aggregation_method' | 'definition.metric_groups' | 'name' | 'updated'>");
}
if (options.fieldsMappedMetric !== undefined) {
localVarQueryParameters['fields[mapped-metric]'] = ObjectSerializer.serialize(options.fieldsMappedMetric, "Array<'updated'>");
}
if (options.fieldsMetric !== undefined) {
localVarQueryParameters['fields[metric]'] = ObjectSerializer.serialize(options.fieldsMetric, "Array<'created' | 'integration' | 'name' | 'updated'>");
}
if (options.include !== undefined) {
localVarQueryParameters['include'] = ObjectSerializer.serialize(options.include, "Array<'custom-metric' | 'metric'>");
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'GET',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: GetMappedMetricResponseCompoundDocument; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetMappedMetricResponseCompoundDocument");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Get all mapped metrics in an account.
*Rate limits*:
Burst: `3/s`
Steady: `60/m` **Scopes:** `metrics:read`
* @summary Get Mapped Metrics
* @param fieldsCustomMetric For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets* @param fieldsMappedMetric For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets* @param fieldsMetric For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets* @param include For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#relationships
*/
public async getMappedMetrics (options: { fieldsCustomMetric?: Array<'created' | 'definition' | 'definition.aggregation_method' | 'definition.metric_groups' | 'name' | 'updated'>, fieldsMappedMetric?: Array<'updated'>, fieldsMetric?: Array<'created' | 'integration' | 'name' | 'updated'>, include?: Array<'custom-metric' | 'metric'>, } = {}): Promise<{ response: AxiosResponse; body: GetMappedMetricResponseCollectionCompoundDocument; }> {
const localVarPath = this.basePath + '/api/mapped-metrics';
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
if (options.fieldsCustomMetric !== undefined) {
localVarQueryParameters['fields[custom-metric]'] = ObjectSerializer.serialize(options.fieldsCustomMetric, "Array<'created' | 'definition' | 'definition.aggregation_method' | 'definition.metric_groups' | 'name' | 'updated'>");
}
if (options.fieldsMappedMetric !== undefined) {
localVarQueryParameters['fields[mapped-metric]'] = ObjectSerializer.serialize(options.fieldsMappedMetric, "Array<'updated'>");
}
if (options.fieldsMetric !== undefined) {
localVarQueryParameters['fields[metric]'] = ObjectSerializer.serialize(options.fieldsMetric, "Array<'created' | 'integration' | 'name' | 'updated'>");
}
if (options.include !== undefined) {
localVarQueryParameters['include'] = ObjectSerializer.serialize(options.include, "Array<'custom-metric' | 'metric'>");
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'GET',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: GetMappedMetricResponseCollectionCompoundDocument; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetMappedMetricResponseCollectionCompoundDocument");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Get a metric with the given metric ID.
*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `metrics:read`
* @summary Get Metric
* @param id Metric ID
* @param fieldsFlow For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets* @param fieldsMetric For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets* @param include For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#relationships
*/
public async getMetric (id: string, options: { fieldsFlow?: Array<'archived' | 'created' | 'name' | 'status' | 'trigger_type' | 'updated'>, fieldsMetric?: Array<'created' | 'integration' | 'name' | 'updated'>, include?: Array<'flow-triggers'>, } = {}): Promise<{ response: AxiosResponse; body: GetMetricResponseCompoundDocument; }> {
const localVarPath = this.basePath + '/api/metrics/{id}'
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling getMetric.');
}
if (options.fieldsFlow !== undefined) {
localVarQueryParameters['fields[flow]'] = ObjectSerializer.serialize(options.fieldsFlow, "Array<'archived' | 'created' | 'name' | 'status' | 'trigger_type' | 'updated'>");
}
if (options.fieldsMetric !== undefined) {
localVarQueryParameters['fields[metric]'] = ObjectSerializer.serialize(options.fieldsMetric, "Array<'created' | 'integration' | 'name' | 'updated'>");
}
if (options.include !== undefined) {
localVarQueryParameters['include'] = ObjectSerializer.serialize(options.include, "Array<'flow-triggers'>");
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'GET',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: GetMetricResponseCompoundDocument; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetMetricResponseCompoundDocument");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Get the metric for the given mapped metric ID (if applicable).
*Rate limits*:
Burst: `3/s`
Steady: `60/m` **Scopes:** `metrics:read`
* @summary Get Metric for Mapped Metric
* @param id The type of mapping.
* @param fieldsMetric For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets
*/
public async getMetricForMappedMetric (id: 'added_to_cart' | 'cancelled_sales' | 'ordered_product' | 'refunded_sales' | 'revenue' | 'started_checkout' | 'viewed_product', options: { fieldsMetric?: Array<'created' | 'integration' | 'name' | 'updated'>, } = {}): Promise<{ response: AxiosResponse; body: GetMetricResponse; }> {
const localVarPath = this.basePath + '/api/mapped-metrics/{id}/metric'
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling getMetricForMappedMetric.');
}
if (options.fieldsMetric !== undefined) {
localVarQueryParameters['fields[metric]'] = ObjectSerializer.serialize(options.fieldsMetric, "Array<'created' | 'integration' | 'name' | 'updated'>");
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'GET',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: GetMetricResponse; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetMetricResponse");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Get the metric for the given metric property ID.
*Rate limits*:
Burst: `1/s`
Steady: `15/m` **Scopes:** `metrics:read`
* @summary Get Metric for Metric Property
* @param id The ID of the metric property
* @param fieldsMetric For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets
*/
public async getMetricForMetricProperty (id: string, options: { fieldsMetric?: Array<'created' | 'integration' | 'name' | 'updated'>, } = {}): Promise<{ response: AxiosResponse; body: GetMetricResponse; }> {
const localVarPath = this.basePath + '/api/metric-properties/{id}/metric'
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling getMetricForMetricProperty.');
}
if (options.fieldsMetric !== undefined) {
localVarQueryParameters['fields[metric]'] = ObjectSerializer.serialize(options.fieldsMetric, "Array<'created' | 'integration' | 'name' | 'updated'>");
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'GET',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: GetMetricResponse; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetMetricResponse");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Get the ID of the metric for the given mapped metric.
*Rate limits*:
Burst: `3/s`
Steady: `60/m` **Scopes:** `metrics:read`
* @summary Get Metric ID for Mapped Metric
* @param id The type of mapping.
*/
public async getMetricIdForMappedMetric (id: 'added_to_cart' | 'cancelled_sales' | 'ordered_product' | 'refunded_sales' | 'revenue' | 'started_checkout' | 'viewed_product', ): Promise<{ response: AxiosResponse; body: GetMappedMetricMetricRelationshipResponse; }> {
const localVarPath = this.basePath + '/api/mapped-metrics/{id}/relationships/metric'
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling getMetricIdForMappedMetric.');
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'GET',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: GetMappedMetricMetricRelationshipResponse; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetMappedMetricMetricRelationshipResponse");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Get the ID of the metric for the given metric property.
*Rate limits*:
Burst: `1/s`
Steady: `15/m` **Scopes:** `metrics:read`
* @summary Get Metric ID for Metric Property
* @param id The ID of the metric property
*/
public async getMetricIdForMetricProperty (id: string, ): Promise<{ response: AxiosResponse; body: GetMetricPropertyMetricRelationshipResponse; }> {
const localVarPath = this.basePath + '/api/metric-properties/{id}/relationships/metric'
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling getMetricIdForMetricProperty.');
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'GET',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: GetMetricPropertyMetricRelationshipResponse; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetMetricPropertyMetricRelationshipResponse");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Get all metrics for the given custom metric ID.
*Rate limits*:
Burst: `3/s`
Steady: `60/m` **Scopes:** `metrics:read`
* @summary Get Metric IDs for Custom Metric
* @param id The ID of the custom metric
*/
public async getMetricIdsForCustomMetric (id: string, ): Promise<{ response: AxiosResponse; body: GetCustomMetricMetricsRelationshipsResponseCollection; }> {
const localVarPath = this.basePath + '/api/custom-metrics/{id}/relationships/metrics'
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling getMetricIdsForCustomMetric.');
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'GET',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: GetCustomMetricMetricsRelationshipsResponseCollection; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetCustomMetricMetricsRelationshipsResponseCollection");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Get a metric property with the given metric property ID.
*Rate limits*:
Burst: `1/s`
Steady: `15/m` **Scopes:** `metrics:read`
* @summary Get Metric Property
* @param id The ID of the metric property
* @param additionalFieldsMetricProperty Request additional fields not included by default in the response. Supported values: \'sample_values\'* @param fieldsMetricProperty For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets* @param fieldsMetric For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets* @param include For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#relationships
*/
public async getMetricProperty (id: string, options: { additionalFieldsMetricProperty?: Array<'sample_values'>, fieldsMetricProperty?: Array<'inferred_type' | 'label' | 'property' | 'sample_values'>, fieldsMetric?: Array<'created' | 'integration' | 'name' | 'updated'>, include?: Array<'metric'>, } = {}): Promise<{ response: AxiosResponse; body: GetMetricPropertyResponseCompoundDocument; }> {
const localVarPath = this.basePath + '/api/metric-properties/{id}'
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling getMetricProperty.');
}
if (options.additionalFieldsMetricProperty !== undefined) {
localVarQueryParameters['additional-fields[metric-property]'] = ObjectSerializer.serialize(options.additionalFieldsMetricProperty, "Array<'sample_values'>");
}
if (options.fieldsMetricProperty !== undefined) {
localVarQueryParameters['fields[metric-property]'] = ObjectSerializer.serialize(options.fieldsMetricProperty, "Array<'inferred_type' | 'label' | 'property' | 'sample_values'>");
}
if (options.fieldsMetric !== undefined) {
localVarQueryParameters['fields[metric]'] = ObjectSerializer.serialize(options.fieldsMetric, "Array<'created' | 'integration' | 'name' | 'updated'>");
}
if (options.include !== undefined) {
localVarQueryParameters['include'] = ObjectSerializer.serialize(options.include, "Array<'metric'>");
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'GET',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: GetMetricPropertyResponseCompoundDocument; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetMetricPropertyResponseCompoundDocument");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Get all metrics in an account. Requests can be filtered by the following fields: integration `name`, integration `category` Returns a maximum of 200 results per page.
*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `metrics:read`
* @summary Get Metrics
* @param fieldsFlow For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets* @param fieldsMetric For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets* @param filter For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#filtering<br>Allowed field(s)/operator(s):<br>`integration.name`: `equals`<br>`integration.category`: `equals`* @param include For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#relationships* @param pageCursor For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#pagination
*/
public async getMetrics (options: { fieldsFlow?: Array<'archived' | 'created' | 'name' | 'status' | 'trigger_type' | 'updated'>, fieldsMetric?: Array<'created' | 'integration' | 'name' | 'updated'>, filter?: string, include?: Array<'flow-triggers'>, pageCursor?: string, } = {}): Promise<{ response: AxiosResponse; body: GetMetricResponseCollectionCompoundDocument; }> {
const localVarPath = this.basePath + '/api/metrics';
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
if (options.fieldsFlow !== undefined) {
localVarQueryParameters['fields[flow]'] = ObjectSerializer.serialize(options.fieldsFlow, "Array<'archived' | 'created' | 'name' | 'status' | 'trigger_type' | 'updated'>");
}
if (options.fieldsMetric !== undefined) {
localVarQueryParameters['fields[metric]'] = ObjectSerializer.serialize(options.fieldsMetric, "Array<'created' | 'integration' | 'name' | 'updated'>");
}
if (options.filter !== undefined) {
localVarQueryParameters['filter'] = ObjectSerializer.serialize(options.filter, "string");
}
if (options.include !== undefined) {
localVarQueryParameters['include'] = ObjectSerializer.serialize(options.include, "Array<'flow-triggers'>");
}
if (options.pageCursor !== undefined) {
localVarQueryParameters['page[cursor]'] = ObjectSerializer.serialize(options.pageCursor, "string");
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'GET',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: GetMetricResponseCollectionCompoundDocument; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetMetricResponseCollectionCompoundDocument");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Get all metrics for the given custom metric ID.
*Rate limits*:
Burst: `3/s`
Steady: `60/m` **Scopes:** `metrics:read`
* @summary Get Metrics for Custom Metric
* @param id The ID of the custom metric
* @param fieldsMetric For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets
*/
public async getMetricsForCustomMetric (id: string, options: { fieldsMetric?: Array<'created' | 'integration' | 'name' | 'updated'>, } = {}): Promise<{ response: AxiosResponse; body: GetMetricResponseCollection; }> {
const localVarPath = this.basePath + '/api/custom-metrics/{id}/metrics'
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling getMetricsForCustomMetric.');
}
if (options.fieldsMetric !== undefined) {
localVarQueryParameters['fields[metric]'] = ObjectSerializer.serialize(options.fieldsMetric, "Array<'created' | 'integration' | 'name' | 'updated'>");
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'GET',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: GetMetricResponseCollection; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetMetricResponseCollection");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Get the metric properties for the given metric ID.
*Rate limits*:
Burst: `1/s`
Steady: `15/m` **Scopes:** `metrics:read`
* @summary Get Properties for Metric
* @param id The ID of the metric
* @param additionalFieldsMetricProperty Request additional fields not included by default in the response. Supported values: \'sample_values\'* @param fieldsMetricProperty For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets
*/
public async getPropertiesForMetric (id: string, options: { additionalFieldsMetricProperty?: Array<'sample_values'>, fieldsMetricProperty?: Array<'inferred_type' | 'label' | 'property' | 'sample_values'>, } = {}): Promise<{ response: AxiosResponse; body: GetMetricPropertyResponseCollection; }> {
const localVarPath = this.basePath + '/api/metrics/{id}/metric-properties'
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling getPropertiesForMetric.');
}
if (options.additionalFieldsMetricProperty !== undefined) {
localVarQueryParameters['additional-fields[metric-property]'] = ObjectSerializer.serialize(options.additionalFieldsMetricProperty, "Array<'sample_values'>");
}
if (options.fieldsMetricProperty !== undefined) {
localVarQueryParameters['fields[metric-property]'] = ObjectSerializer.serialize(options.fieldsMetricProperty, "Array<'inferred_type' | 'label' | 'property' | 'sample_values'>");
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'GET',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: GetMetricPropertyResponseCollection; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetMetricPropertyResponseCollection");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Get the IDs of metric properties for the given metric.
*Rate limits*:
Burst: `1/s`
Steady: `15/m` **Scopes:** `metrics:read`
* @summary Get Property IDs for Metric
* @param id The ID of the metric
*/
public async getPropertyIdsForMetric (id: string, ): Promise<{ response: AxiosResponse; body: GetMetricPropertiesRelationshipsResponseCollection; }> {
const localVarPath = this.basePath + '/api/metrics/{id}/relationships/metric-properties'
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling getPropertyIdsForMetric.');
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'GET',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: GetMetricPropertiesRelationshipsResponseCollection; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetMetricPropertiesRelationshipsResponseCollection");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Query and aggregate event data associated with a metric, including native Klaviyo metrics, integration-specific metrics, and custom events (not to be confused with [custom metrics](https://developers.klaviyo.com/en/reference/custom_metrics_api_overview), which are not supported at this time). Queries must be passed in the JSON body of your `POST` request. To request campaign and flow performance data that matches the data shown in Klaviyo\'s UI, we recommend the [Reporting API](https://developers.klaviyo.com/en/reference/reporting_api_overview). Results can be filtered and grouped by time, event, or profile dimensions. To learn more about how to use this endpoint, check out our new [Using the Query Metric Aggregates Endpoint guide](https://developers.klaviyo.com/en/docs/using-the-query-metric-aggregates-endpoint). For a comprehensive list of request body parameters, native Klaviyo metrics, and their associated attributes for grouping and filtering, please refer to the [metrics attributes guide](https://developers.klaviyo.com/en/docs/supported_metrics_and_attributes).
*Rate limits*:
Burst: `3/s`
Steady: `60/m` **Scopes:** `metrics:read`
* @summary Query Metric Aggregates
* @param metricAggregateQuery Retrieve Metric Aggregations
*/
public async queryMetricAggregates (metricAggregateQuery: MetricAggregateQuery, ): Promise<{ response: AxiosResponse; body: PostMetricAggregateResponse; }> {
const localVarPath = this.basePath + '/api/metric-aggregates';
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
// verify required parameter 'metricAggregateQuery' is not null or undefined
if (metricAggregateQuery === null || metricAggregateQuery === undefined) {
throw new Error('Required parameter metricAggregateQuery was null or undefined when calling queryMetricAggregates.');
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'POST',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
data: ObjectSerializer.serialize(metricAggregateQuery, "MetricAggregateQuery")
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: PostMetricAggregateResponse; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "PostMetricAggregateResponse");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Update a custom metric with the given custom metric ID.
*Rate limits*:
Burst: `1/s`
Steady: `15/m`
Daily: `15/d` **Scopes:** `metrics:write`
* @summary Update Custom Metric
* @param id The ID of the custom metric* @param customMetricPartialUpdateQuery Update a custom metric by ID.
*/
public async updateCustomMetric (id: string, customMetricPartialUpdateQuery: CustomMetricPartialUpdateQuery, ): Promise<{ response: AxiosResponse; body: PatchCustomMetricResponse; }> {
const localVarPath = this.basePath + '/api/custom-metrics/{id}'
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling updateCustomMetric.');
}
// verify required parameter 'customMetricPartialUpdateQuery' is not null or undefined
if (customMetricPartialUpdateQuery === null || customMetricPartialUpdateQuery === undefined) {
throw new Error('Required parameter customMetricPartialUpdateQuery was null or undefined when calling updateCustomMetric.');
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'PATCH',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
data: ObjectSerializer.serialize(customMetricPartialUpdateQuery, "CustomMetricPartialUpdateQuery")
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: PatchCustomMetricResponse; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "PatchCustomMetricResponse");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
/**
* Update the mapped metric with the given ID.
*Rate limits*:
Burst: `1/s`
Steady: `15/m`
Daily: `30/d` **Scopes:** `metrics:write`
* @summary Update Mapped Metric
* @param id The type of mapping.* @param mappedMetricPartialUpdateQuery Update a mapped metric by ID
*/
public async updateMappedMetric (id: 'added_to_cart' | 'cancelled_sales' | 'ordered_product' | 'refunded_sales' | 'revenue' | 'started_checkout' | 'viewed_product', mappedMetricPartialUpdateQuery: MappedMetricPartialUpdateQuery, ): Promise<{ response: AxiosResponse; body: PatchMappedMetricResponse; }> {
const localVarPath = this.basePath + '/api/mapped-metrics/{id}'
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (Object).assign({}, this._defaultHeaders);
const produces = ['application/vnd.api+json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling updateMappedMetric.');
}
// verify required parameter 'mappedMetricPartialUpdateQuery' is not null or undefined
if (mappedMetricPartialUpdateQuery === null || mappedMetricPartialUpdateQuery === undefined) {
throw new Error('Required parameter mappedMetricPartialUpdateQuery was null or undefined when calling updateMappedMetric.');
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'PATCH',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
data: ObjectSerializer.serialize(mappedMetricPartialUpdateQuery, "MappedMetricPartialUpdateQuery")
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: PatchMappedMetricResponse; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "PatchMappedMetricResponse");
return ({response: axiosResponse, body: body});
} catch (error) {
if (await this.session.refreshAndRetry(error, retried)) {
await this.session.applyToRequest(config)
return request(config, true)
}
throw error
}
}
return request(config)
}
}
export interface MetricsApi {
/**
* Alias of {@link MetricsApi.getCustomMetricForMappedMetric}
*
* @deprecated Use {@link MetricsApi.getCustomMetricForMappedMetric} instead
*/
getMappedMetricCustomMetric: typeof MetricsApi.prototype.getCustomMetricForMappedMetric;
}
MetricsApi.prototype.getMappedMetricCustomMetric = MetricsApi.prototype.getCustomMetricForMappedMetric
export interface MetricsApi {
/**
* Alias of {@link MetricsApi.getCustomMetricIdForMappedMetric}
*
* @deprecated Use {@link MetricsApi.getCustomMetricIdForMappedMetric} instead
*/
getMappedMetricRelationshipsCustomMetric: typeof MetricsApi.prototype.getCustomMetricIdForMappedMetric;
}
MetricsApi.prototype.getMappedMetricRelationshipsCustomMetric = MetricsApi.prototype.getCustomMetricIdForMappedMetric
export interface MetricsApi {
/**
* Alias of {@link MetricsApi.getFlowsTriggeredByMetric}
*
* @deprecated Use {@link MetricsApi.getFlowsTriggeredByMetric} instead
*/
getFlowTriggersForMetric: typeof MetricsApi.prototype.getFlowsTriggeredByMetric;
}
MetricsApi.prototype.getFlowTriggersForMetric = MetricsApi.prototype.getFlowsTriggeredByMetric
export interface MetricsApi {
/**
* Alias of {@link MetricsApi.getFlowsTriggeredByMetric}
*
* @deprecated Use {@link MetricsApi.getFlowsTriggeredByMetric} instead
*/
getMetricFlowTriggers: typeof MetricsApi.prototype.getFlowsTriggeredByMetric;
}
MetricsApi.prototype.getMetricFlowTriggers = MetricsApi.prototype.getFlowsTriggeredByMetric
export interface MetricsApi {
/**
* Alias of {@link MetricsApi.getIdsForFlowsTriggeredByMetric}
*
* @deprecated Use {@link MetricsApi.getIdsForFlowsTriggeredByMetric} instead
*/
getFlowTriggerIdsForMetric: typeof MetricsApi.prototype.getIdsForFlowsTriggeredByMetric;
}
MetricsApi.prototype.getFlowTriggerIdsForMetric = MetricsApi.prototype.getIdsForFlowsTriggeredByMetric
export interface MetricsApi {
/**
* Alias of {@link MetricsApi.getIdsForFlowsTriggeredByMetric}
*
* @deprecated Use {@link MetricsApi.getIdsForFlowsTriggeredByMetric} instead
*/
getMetricRelationshipsFlowTriggers: typeof MetricsApi.prototype.getIdsForFlowsTriggeredByMetric;
}
MetricsApi.prototype.getMetricRelationshipsFlowTriggers = MetricsApi.prototype.getIdsForFlowsTriggeredByMetric
export interface MetricsApi {
/**
* Alias of {@link MetricsApi.getMetricForMappedMetric}
*
* @deprecated Use {@link MetricsApi.getMetricForMappedMetric} instead
*/
getMappedMetricMetric: typeof MetricsApi.prototype.getMetricForMappedMetric;
}
MetricsApi.prototype.getMappedMetricMetric = MetricsApi.prototype.getMetricForMappedMetric
export interface MetricsApi {
/**
* Alias of {@link MetricsApi.getMetricForMetricProperty}
*
* @deprecated Use {@link MetricsApi.getMetricForMetricProperty} instead
*/
getMetricPropertyMetric: typeof MetricsApi.prototype.getMetricForMetricProperty;
}
MetricsApi.prototype.getMetricPropertyMetric = MetricsApi.prototype.getMetricForMetricProperty
export interface MetricsApi {
/**
* Alias of {@link MetricsApi.getMetricIdForMappedMetric}
*
* @deprecated Use {@link MetricsApi.getMetricIdForMappedMetric} instead
*/
getMappedMetricRelationshipsMetric: typeof MetricsApi.prototype.getMetricIdForMappedMetric;
}
MetricsApi.prototype.getMappedMetricRelationshipsMetric = MetricsApi.prototype.getMetricIdForMappedMetric
export interface MetricsApi {
/**
* Alias of {@link MetricsApi.getMetricIdForMetricProperty}
*
* @deprecated Use {@link MetricsApi.getMetricIdForMetricProperty} instead
*/
getMetricPropertyRelationshipsMetric: typeof MetricsApi.prototype.getMetricIdForMetricProperty;
}
MetricsApi.prototype.getMetricPropertyRelationshipsMetric = MetricsApi.prototype.getMetricIdForMetricProperty
export interface MetricsApi {
/**
* Alias of {@link MetricsApi.getMetricIdsForCustomMetric}
*
* @deprecated Use {@link MetricsApi.getMetricIdsForCustomMetric} instead
*/
getCustomMetricRelationshipsMetrics: typeof MetricsApi.prototype.getMetricIdsForCustomMetric;
}
MetricsApi.prototype.getCustomMetricRelationshipsMetrics = MetricsApi.prototype.getMetricIdsForCustomMetric
export interface MetricsApi {
/**
* Alias of {@link MetricsApi.getMetricsForCustomMetric}
*
* @deprecated Use {@link MetricsApi.getMetricsForCustomMetric} instead
*/
getCustomMetricMetrics: typeof MetricsApi.prototype.getMetricsForCustomMetric;
}
MetricsApi.prototype.getCustomMetricMetrics = MetricsApi.prototype.getMetricsForCustomMetric
export interface MetricsApi {
/**
* Alias of {@link MetricsApi.getPropertiesForMetric}
*
* @deprecated Use {@link MetricsApi.getPropertiesForMetric} instead
*/
getMetricMetricProperties: typeof MetricsApi.prototype.getPropertiesForMetric;
}
MetricsApi.prototype.getMetricMetricProperties = MetricsApi.prototype.getPropertiesForMetric
export interface MetricsApi {
/**
* Alias of {@link MetricsApi.getPropertiesForMetric}
*
* @deprecated Use {@link MetricsApi.getPropertiesForMetric} instead
*/
getMetricProperties: typeof MetricsApi.prototype.getPropertiesForMetric;
}
MetricsApi.prototype.getMetricProperties = MetricsApi.prototype.getPropertiesForMetric
export interface MetricsApi {
/**
* Alias of {@link MetricsApi.getPropertyIdsForMetric}
*
* @deprecated Use {@link MetricsApi.getPropertyIdsForMetric} instead
*/
getMetricRelationshipsMetricProperties: typeof MetricsApi.prototype.getPropertyIdsForMetric;
}
MetricsApi.prototype.getMetricRelationshipsMetricProperties = MetricsApi.prototype.getPropertyIdsForMetric
export interface MetricsApi {
/**
* Alias of {@link MetricsApi.getPropertyIdsForMetric}
*
* @deprecated Use {@link MetricsApi.getPropertyIdsForMetric} instead
*/
getMetricRelationshipsProperties: typeof MetricsApi.prototype.getPropertyIdsForMetric;
}
MetricsApi.prototype.getMetricRelationshipsProperties = MetricsApi.prototype.getPropertyIdsForMetric
export interface MetricsApi {
/**
* Alias of {@link MetricsApi.queryMetricAggregates}
*
* @deprecated Use {@link MetricsApi.queryMetricAggregates} instead
*/
createMetricAggregate: typeof MetricsApi.prototype.queryMetricAggregates;
}
MetricsApi.prototype.createMetricAggregate = MetricsApi.prototype.queryMetricAggregates