/**
* 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 { GetAccounts4XXResponse } from '../model/getAccounts4XXResponse';
import { GetFlowResponseCollection } from '../model/getFlowResponseCollection';
import { GetSegmentFlowTriggersRelationshipsResponseCollection } from '../model/getSegmentFlowTriggersRelationshipsResponseCollection';
import { GetSegmentListResponseCollectionCompoundDocument } from '../model/getSegmentListResponseCollectionCompoundDocument';
import { GetSegmentMemberResponseCollection } from '../model/getSegmentMemberResponseCollection';
import { GetSegmentProfilesRelationshipsResponseCollection } from '../model/getSegmentProfilesRelationshipsResponseCollection';
import { GetSegmentRetrieveResponseCompoundDocument } from '../model/getSegmentRetrieveResponseCompoundDocument';
import { GetSegmentTagsRelationshipsResponseCollection } from '../model/getSegmentTagsRelationshipsResponseCollection';
import { GetTagResponseCollection } from '../model/getTagResponseCollection';
import { PatchSegmentPartialUpdateResponse } from '../model/patchSegmentPartialUpdateResponse';
import { PostSegmentCreateResponse } from '../model/postSegmentCreateResponse';
import { SegmentCreateQuery } from '../model/segmentCreateQuery';
import { SegmentPartialUpdateQuery } from '../model/segmentPartialUpdateQuery';
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 SegmentsApi {
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 segment.
*Rate limits*:
Burst: `1/s`
Steady: `15/m`
Daily: `100/d` **Scopes:** `segments:write`
* @summary Create Segment
* @param segmentCreateQuery
*/
public async createSegment (segmentCreateQuery: SegmentCreateQuery, ): Promise<{ response: AxiosResponse; body: PostSegmentCreateResponse; }> {
const localVarPath = this.basePath + '/api/segments';
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 'segmentCreateQuery' is not null or undefined
if (segmentCreateQuery === null || segmentCreateQuery === undefined) {
throw new Error('Required parameter segmentCreateQuery was null or undefined when calling createSegment.');
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'POST',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
data: ObjectSerializer.serialize(segmentCreateQuery, "SegmentCreateQuery")
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: PostSegmentCreateResponse; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "PostSegmentCreateResponse");
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 segment with the given segment ID.
*Rate limits*:
Burst: `3/s`
Steady: `60/m` **Scopes:** `segments:write`
* @summary Delete Segment
* @param id
*/
public async deleteSegment (id: string, ): Promise<{ response: AxiosResponse; body?: any; }> {
const localVarPath = this.basePath + '/api/segments/{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 deleteSegment.');
}
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 all flows where the given segment ID is being used as the trigger.
*Rate limits*:
Burst: `3/s`
Steady: `60/m` **Scopes:** `flows:read` `segments:read`
* @summary Get Flows Triggered by Segment
* @param id Primary key that uniquely identifies this segment. Generated by Klaviyo.
* @param fieldsFlow For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets
*/
public async getFlowsTriggeredBySegment (id: string, options: { fieldsFlow?: Array<'archived' | 'created' | 'name' | 'status' | 'trigger_type' | 'updated'>, } = {}): Promise<{ response: AxiosResponse; body: GetFlowResponseCollection; }> {
const localVarPath = this.basePath + '/api/segments/{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 getFlowsTriggeredBySegment.');
}
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 segment is being used as the trigger.
*Rate limits*:
Burst: `3/s`
Steady: `60/m` **Scopes:** `flows:read` `segments:read`
* @summary Get IDs for Flows Triggered by Segment
* @param id Primary key that uniquely identifies this segment. Generated by Klaviyo.
*/
public async getIdsForFlowsTriggeredBySegment (id: string, ): Promise<{ response: AxiosResponse; body: GetSegmentFlowTriggersRelationshipsResponseCollection; }> {
const localVarPath = this.basePath + '/api/segments/{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 getIdsForFlowsTriggeredBySegment.');
}
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: GetSegmentFlowTriggersRelationshipsResponseCollection; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetSegmentFlowTriggersRelationshipsResponseCollection");
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 profile membership [relationships](https://developers.klaviyo.com/en/reference/api_overview#relationships) for the given segment ID.
*Rate limits*:
Burst: `75/s`
Steady: `750/m` **Scopes:** `profiles:read` `segments:read`
* @summary Get Profile IDs for Segment
* @param id Primary key that uniquely identifies this segment. Generated by Klaviyo.
* @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>`profile_id`: `any`, `equals`<br>`email`: `any`, `equals`<br>`phone_number`: `any`, `equals`<br>`push_token`: `any`, `equals`<br>`_kx`: `equals`<br>`joined_group_at`: `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than`* @param pageCursor For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#pagination* @param pageSize Default: 20. Min: 1. Max: 100.* @param sort For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sorting
*/
public async getProfileIdsForSegment (id: string, options: { filter?: string, pageCursor?: string, pageSize?: number, sort?: 'joined_group_at' | '-joined_group_at', } = {}): Promise<{ response: AxiosResponse; body: GetSegmentProfilesRelationshipsResponseCollection; }> {
const localVarPath = this.basePath + '/api/segments/{id}/relationships/profiles'
.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 getProfileIdsForSegment.');
}
if (options.filter !== undefined) {
localVarQueryParameters['filter'] = ObjectSerializer.serialize(options.filter, "string");
}
if (options.pageCursor !== undefined) {
localVarQueryParameters['page[cursor]'] = ObjectSerializer.serialize(options.pageCursor, "string");
}
if (options.pageSize !== undefined) {
localVarQueryParameters['page[size]'] = ObjectSerializer.serialize(options.pageSize, "number");
}
if (options.sort !== undefined) {
localVarQueryParameters['sort'] = ObjectSerializer.serialize(options.sort, "'joined_group_at' | '-joined_group_at'");
}
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: GetSegmentProfilesRelationshipsResponseCollection; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetSegmentProfilesRelationshipsResponseCollection");
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 profiles within a segment with the given segment ID. Filter to request a subset of all profiles. Profiles can be filtered by `email`, `phone_number`, `push_token`, and `joined_group_at` fields. Profiles can be sorted by the following fields, in ascending and descending order: `joined_group_at`
*Rate limits*:
Burst: `75/s`
Steady: `750/m` **Scopes:** `profiles:read` `segments:read`
* @summary Get Profiles for Segment
* @param id Primary key that uniquely identifies this segment. Generated by Klaviyo.
* @param additionalFieldsProfile Request additional fields not included by default in the response. Supported values: \'subscriptions\', \'predictive_analytics\'* @param fieldsProfile 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>`profile_id`: `any`, `equals`<br>`email`: `any`, `equals`<br>`phone_number`: `any`, `equals`<br>`push_token`: `any`, `equals`<br>`_kx`: `equals`<br>`joined_group_at`: `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than`* @param pageCursor For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#pagination* @param pageSize Default: 20. Min: 1. Max: 100.* @param sort For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sorting
*/
public async getProfilesForSegment (id: string, options: { additionalFieldsProfile?: Array<'subscriptions' | 'predictive_analytics'>, fieldsProfile?: Array<'created' | 'email' | 'external_id' | 'first_name' | 'image' | 'joined_group_at' | 'last_event_date' | 'last_name' | 'locale' | 'location' | 'location.address1' | 'location.address2' | 'location.city' | 'location.country' | 'location.ip' | 'location.latitude' | 'location.longitude' | 'location.region' | 'location.timezone' | 'location.zip' | 'organization' | 'phone_number' | 'predictive_analytics' | 'predictive_analytics.average_days_between_orders' | 'predictive_analytics.average_order_value' | 'predictive_analytics.churn_probability' | 'predictive_analytics.expected_date_of_next_order' | 'predictive_analytics.historic_clv' | 'predictive_analytics.historic_number_of_orders' | 'predictive_analytics.predicted_clv' | 'predictive_analytics.predicted_number_of_orders' | 'predictive_analytics.ranked_channel_affinity' | 'predictive_analytics.total_clv' | 'properties' | 'subscriptions' | 'subscriptions.email' | 'subscriptions.email.marketing' | 'subscriptions.email.marketing.can_receive_email_marketing' | 'subscriptions.email.marketing.consent' | 'subscriptions.email.marketing.consent_timestamp' | 'subscriptions.email.marketing.custom_method_detail' | 'subscriptions.email.marketing.double_optin' | 'subscriptions.email.marketing.last_updated' | 'subscriptions.email.marketing.list_suppressions' | 'subscriptions.email.marketing.method' | 'subscriptions.email.marketing.method_detail' | 'subscriptions.email.marketing.suppression' | 'subscriptions.mobile_push' | 'subscriptions.mobile_push.marketing' | 'subscriptions.mobile_push.marketing.can_receive_push_marketing' | 'subscriptions.mobile_push.marketing.consent' | 'subscriptions.mobile_push.marketing.consent_timestamp' | 'subscriptions.sms' | 'subscriptions.sms.marketing' | 'subscriptions.sms.marketing.can_receive_sms_marketing' | 'subscriptions.sms.marketing.consent' | 'subscriptions.sms.marketing.consent_timestamp' | 'subscriptions.sms.marketing.last_updated' | 'subscriptions.sms.marketing.method' | 'subscriptions.sms.marketing.method_detail' | 'subscriptions.sms.transactional' | 'subscriptions.sms.transactional.can_receive_sms_transactional' | 'subscriptions.sms.transactional.consent' | 'subscriptions.sms.transactional.consent_timestamp' | 'subscriptions.sms.transactional.last_updated' | 'subscriptions.sms.transactional.method' | 'subscriptions.sms.transactional.method_detail' | 'subscriptions.whatsapp' | 'subscriptions.whatsapp.conversational' | 'subscriptions.whatsapp.conversational.can_receive' | 'subscriptions.whatsapp.conversational.consent' | 'subscriptions.whatsapp.conversational.consent_timestamp' | 'subscriptions.whatsapp.conversational.created_timestamp' | 'subscriptions.whatsapp.conversational.last_updated' | 'subscriptions.whatsapp.conversational.metadata' | 'subscriptions.whatsapp.conversational.phone_number' | 'subscriptions.whatsapp.conversational.valid_until' | 'subscriptions.whatsapp.marketing' | 'subscriptions.whatsapp.marketing.can_receive' | 'subscriptions.whatsapp.marketing.consent' | 'subscriptions.whatsapp.marketing.consent_timestamp' | 'subscriptions.whatsapp.marketing.created_timestamp' | 'subscriptions.whatsapp.marketing.last_updated' | 'subscriptions.whatsapp.marketing.metadata' | 'subscriptions.whatsapp.marketing.phone_number' | 'subscriptions.whatsapp.marketing.valid_until' | 'subscriptions.whatsapp.transactional' | 'subscriptions.whatsapp.transactional.can_receive' | 'subscriptions.whatsapp.transactional.consent' | 'subscriptions.whatsapp.transactional.consent_timestamp' | 'subscriptions.whatsapp.transactional.created_timestamp' | 'subscriptions.whatsapp.transactional.last_updated' | 'subscriptions.whatsapp.transactional.metadata' | 'subscriptions.whatsapp.transactional.phone_number' | 'subscriptions.whatsapp.transactional.valid_until' | 'title' | 'updated'>, filter?: string, pageCursor?: string, pageSize?: number, sort?: 'joined_group_at' | '-joined_group_at', } = {}): Promise<{ response: AxiosResponse; body: GetSegmentMemberResponseCollection; }> {
const localVarPath = this.basePath + '/api/segments/{id}/profiles'
.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 getProfilesForSegment.');
}
if (options.additionalFieldsProfile !== undefined) {
localVarQueryParameters['additional-fields[profile]'] = ObjectSerializer.serialize(options.additionalFieldsProfile, "Array<'subscriptions' | 'predictive_analytics'>");
}
if (options.fieldsProfile !== undefined) {
localVarQueryParameters['fields[profile]'] = ObjectSerializer.serialize(options.fieldsProfile, "Array<'created' | 'email' | 'external_id' | 'first_name' | 'image' | 'joined_group_at' | 'last_event_date' | 'last_name' | 'locale' | 'location' | 'location.address1' | 'location.address2' | 'location.city' | 'location.country' | 'location.ip' | 'location.latitude' | 'location.longitude' | 'location.region' | 'location.timezone' | 'location.zip' | 'organization' | 'phone_number' | 'predictive_analytics' | 'predictive_analytics.average_days_between_orders' | 'predictive_analytics.average_order_value' | 'predictive_analytics.churn_probability' | 'predictive_analytics.expected_date_of_next_order' | 'predictive_analytics.historic_clv' | 'predictive_analytics.historic_number_of_orders' | 'predictive_analytics.predicted_clv' | 'predictive_analytics.predicted_number_of_orders' | 'predictive_analytics.ranked_channel_affinity' | 'predictive_analytics.total_clv' | 'properties' | 'subscriptions' | 'subscriptions.email' | 'subscriptions.email.marketing' | 'subscriptions.email.marketing.can_receive_email_marketing' | 'subscriptions.email.marketing.consent' | 'subscriptions.email.marketing.consent_timestamp' | 'subscriptions.email.marketing.custom_method_detail' | 'subscriptions.email.marketing.double_optin' | 'subscriptions.email.marketing.last_updated' | 'subscriptions.email.marketing.list_suppressions' | 'subscriptions.email.marketing.method' | 'subscriptions.email.marketing.method_detail' | 'subscriptions.email.marketing.suppression' | 'subscriptions.mobile_push' | 'subscriptions.mobile_push.marketing' | 'subscriptions.mobile_push.marketing.can_receive_push_marketing' | 'subscriptions.mobile_push.marketing.consent' | 'subscriptions.mobile_push.marketing.consent_timestamp' | 'subscriptions.sms' | 'subscriptions.sms.marketing' | 'subscriptions.sms.marketing.can_receive_sms_marketing' | 'subscriptions.sms.marketing.consent' | 'subscriptions.sms.marketing.consent_timestamp' | 'subscriptions.sms.marketing.last_updated' | 'subscriptions.sms.marketing.method' | 'subscriptions.sms.marketing.method_detail' | 'subscriptions.sms.transactional' | 'subscriptions.sms.transactional.can_receive_sms_transactional' | 'subscriptions.sms.transactional.consent' | 'subscriptions.sms.transactional.consent_timestamp' | 'subscriptions.sms.transactional.last_updated' | 'subscriptions.sms.transactional.method' | 'subscriptions.sms.transactional.method_detail' | 'subscriptions.whatsapp' | 'subscriptions.whatsapp.conversational' | 'subscriptions.whatsapp.conversational.can_receive' | 'subscriptions.whatsapp.conversational.consent' | 'subscriptions.whatsapp.conversational.consent_timestamp' | 'subscriptions.whatsapp.conversational.created_timestamp' | 'subscriptions.whatsapp.conversational.last_updated' | 'subscriptions.whatsapp.conversational.metadata' | 'subscriptions.whatsapp.conversational.phone_number' | 'subscriptions.whatsapp.conversational.valid_until' | 'subscriptions.whatsapp.marketing' | 'subscriptions.whatsapp.marketing.can_receive' | 'subscriptions.whatsapp.marketing.consent' | 'subscriptions.whatsapp.marketing.consent_timestamp' | 'subscriptions.whatsapp.marketing.created_timestamp' | 'subscriptions.whatsapp.marketing.last_updated' | 'subscriptions.whatsapp.marketing.metadata' | 'subscriptions.whatsapp.marketing.phone_number' | 'subscriptions.whatsapp.marketing.valid_until' | 'subscriptions.whatsapp.transactional' | 'subscriptions.whatsapp.transactional.can_receive' | 'subscriptions.whatsapp.transactional.consent' | 'subscriptions.whatsapp.transactional.consent_timestamp' | 'subscriptions.whatsapp.transactional.created_timestamp' | 'subscriptions.whatsapp.transactional.last_updated' | 'subscriptions.whatsapp.transactional.metadata' | 'subscriptions.whatsapp.transactional.phone_number' | 'subscriptions.whatsapp.transactional.valid_until' | 'title' | 'updated'>");
}
if (options.filter !== undefined) {
localVarQueryParameters['filter'] = ObjectSerializer.serialize(options.filter, "string");
}
if (options.pageCursor !== undefined) {
localVarQueryParameters['page[cursor]'] = ObjectSerializer.serialize(options.pageCursor, "string");
}
if (options.pageSize !== undefined) {
localVarQueryParameters['page[size]'] = ObjectSerializer.serialize(options.pageSize, "number");
}
if (options.sort !== undefined) {
localVarQueryParameters['sort'] = ObjectSerializer.serialize(options.sort, "'joined_group_at' | '-joined_group_at'");
}
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: GetSegmentMemberResponseCollection; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetSegmentMemberResponseCollection");
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 segment with the given segment ID.
*Rate limits*:
Burst: `75/s`
Steady: `750/m`
Rate limits when using the `additional-fields[segment]=profile_count` parameter in your API request:
Burst: `1/s`
Steady: `15/m`
To learn more about how the `additional-fields` parameter impacts rate limits, check out our [Rate limits, status codes, and errors](https://developers.klaviyo.com/en/v2026-04-15/docs/rate_limits_and_error_handling) guide. **Scopes:** `segments:read`
* @summary Get Segment
* @param id
* @param additionalFieldsSegment Request additional fields not included by default in the response. Supported values: \'profile_count\'* @param fieldsFlow For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets* @param fieldsSegment For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets* @param fieldsTag 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 getSegment (id: string, options: { additionalFieldsSegment?: Array<'profile_count'>, fieldsFlow?: Array<'archived' | 'created' | 'name' | 'status' | 'trigger_type' | 'updated'>, fieldsSegment?: Array<'created' | 'definition' | 'definition.condition_groups' | 'is_active' | 'is_processing' | 'is_starred' | 'name' | 'profile_count' | 'updated'>, fieldsTag?: Array<'name'>, include?: Array<'flow-triggers' | 'tags'>, } = {}): Promise<{ response: AxiosResponse; body: GetSegmentRetrieveResponseCompoundDocument; }> {
const localVarPath = this.basePath + '/api/segments/{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 getSegment.');
}
if (options.additionalFieldsSegment !== undefined) {
localVarQueryParameters['additional-fields[segment]'] = ObjectSerializer.serialize(options.additionalFieldsSegment, "Array<'profile_count'>");
}
if (options.fieldsFlow !== undefined) {
localVarQueryParameters['fields[flow]'] = ObjectSerializer.serialize(options.fieldsFlow, "Array<'archived' | 'created' | 'name' | 'status' | 'trigger_type' | 'updated'>");
}
if (options.fieldsSegment !== undefined) {
localVarQueryParameters['fields[segment]'] = ObjectSerializer.serialize(options.fieldsSegment, "Array<'created' | 'definition' | 'definition.condition_groups' | 'is_active' | 'is_processing' | 'is_starred' | 'name' | 'profile_count' | 'updated'>");
}
if (options.fieldsTag !== undefined) {
localVarQueryParameters['fields[tag]'] = ObjectSerializer.serialize(options.fieldsTag, "Array<'name'>");
}
if (options.include !== undefined) {
localVarQueryParameters['include'] = ObjectSerializer.serialize(options.include, "Array<'flow-triggers' | 'tags'>");
}
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: GetSegmentRetrieveResponseCompoundDocument; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetSegmentRetrieveResponseCompoundDocument");
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 segments in an account. Filter to request a subset of all segments. Segments can be filtered by `name`, `created`, and `updated` fields. Returns a maximum of 10 results per page.
*Rate limits*:
Burst: `75/s`
Steady: `750/m` **Scopes:** `segments:read`
* @summary Get Segments
* @param fieldsFlow For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets* @param fieldsSegment For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets* @param fieldsTag 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>`name`: `any`, `equals`<br>`id`: `any`, `equals`<br>`created`: `greater-than`<br>`updated`: `greater-than`<br>`is_active`: `any`, `equals`<br>`is_starred`: `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* @param sort For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sorting
*/
public async getSegments (options: { fieldsFlow?: Array<'archived' | 'created' | 'name' | 'status' | 'trigger_type' | 'updated'>, fieldsSegment?: Array<'created' | 'definition' | 'definition.condition_groups' | 'is_active' | 'is_processing' | 'is_starred' | 'name' | 'updated'>, fieldsTag?: Array<'name'>, filter?: string, include?: Array<'flow-triggers' | 'tags'>, pageCursor?: string, sort?: 'created' | '-created' | 'id' | '-id' | 'name' | '-name' | 'updated' | '-updated', } = {}): Promise<{ response: AxiosResponse; body: GetSegmentListResponseCollectionCompoundDocument; }> {
const localVarPath = this.basePath + '/api/segments';
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.fieldsSegment !== undefined) {
localVarQueryParameters['fields[segment]'] = ObjectSerializer.serialize(options.fieldsSegment, "Array<'created' | 'definition' | 'definition.condition_groups' | 'is_active' | 'is_processing' | 'is_starred' | 'name' | 'updated'>");
}
if (options.fieldsTag !== undefined) {
localVarQueryParameters['fields[tag]'] = ObjectSerializer.serialize(options.fieldsTag, "Array<'name'>");
}
if (options.filter !== undefined) {
localVarQueryParameters['filter'] = ObjectSerializer.serialize(options.filter, "string");
}
if (options.include !== undefined) {
localVarQueryParameters['include'] = ObjectSerializer.serialize(options.include, "Array<'flow-triggers' | 'tags'>");
}
if (options.pageCursor !== undefined) {
localVarQueryParameters['page[cursor]'] = ObjectSerializer.serialize(options.pageCursor, "string");
}
if (options.sort !== undefined) {
localVarQueryParameters['sort'] = ObjectSerializer.serialize(options.sort, "'created' | '-created' | 'id' | '-id' | 'name' | '-name' | 'updated' | '-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: GetSegmentListResponseCollectionCompoundDocument; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetSegmentListResponseCollectionCompoundDocument");
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)
}
/**
* If `related_resource` is `tags`, returns the tag IDs of all tags associated with the given segment ID.
*Rate limits*:
Burst: `3/s`
Steady: `60/m` **Scopes:** `segments:read` `tags:read`
* @summary Get Tag IDs for Segment
* @param id
*/
public async getTagIdsForSegment (id: string, ): Promise<{ response: AxiosResponse; body: GetSegmentTagsRelationshipsResponseCollection; }> {
const localVarPath = this.basePath + '/api/segments/{id}/relationships/tags'
.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 getTagIdsForSegment.');
}
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: GetSegmentTagsRelationshipsResponseCollection; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetSegmentTagsRelationshipsResponseCollection");
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)
}
/**
* Return all tags associated with the given segment ID.
*Rate limits*:
Burst: `3/s`
Steady: `60/m` **Scopes:** `segments:read` `tags:read`
* @summary Get Tags for Segment
* @param id
* @param fieldsTag For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets
*/
public async getTagsForSegment (id: string, options: { fieldsTag?: Array<'name'>, } = {}): Promise<{ response: AxiosResponse; body: GetTagResponseCollection; }> {
const localVarPath = this.basePath + '/api/segments/{id}/tags'
.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 getTagsForSegment.');
}
if (options.fieldsTag !== undefined) {
localVarQueryParameters['fields[tag]'] = ObjectSerializer.serialize(options.fieldsTag, "Array<'name'>");
}
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: GetTagResponseCollection; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetTagResponseCollection");
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 segment with the given segment ID.
*Rate limits*:
Burst: `1/s`
Steady: `15/m`
Daily: `100/d` **Scopes:** `segments:write`
* @summary Update Segment
* @param id * @param segmentPartialUpdateQuery
*/
public async updateSegment (id: string, segmentPartialUpdateQuery: SegmentPartialUpdateQuery, ): Promise<{ response: AxiosResponse; body: PatchSegmentPartialUpdateResponse; }> {
const localVarPath = this.basePath + '/api/segments/{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 updateSegment.');
}
// verify required parameter 'segmentPartialUpdateQuery' is not null or undefined
if (segmentPartialUpdateQuery === null || segmentPartialUpdateQuery === undefined) {
throw new Error('Required parameter segmentPartialUpdateQuery was null or undefined when calling updateSegment.');
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'PATCH',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
data: ObjectSerializer.serialize(segmentPartialUpdateQuery, "SegmentPartialUpdateQuery")
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: PatchSegmentPartialUpdateResponse; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "PatchSegmentPartialUpdateResponse");
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 SegmentsApi {
/**
* Alias of {@link SegmentsApi.getFlowsTriggeredBySegment}
*
* @deprecated Use {@link SegmentsApi.getFlowsTriggeredBySegment} instead
*/
getFlowTriggersForSegment: typeof SegmentsApi.prototype.getFlowsTriggeredBySegment;
}
SegmentsApi.prototype.getFlowTriggersForSegment = SegmentsApi.prototype.getFlowsTriggeredBySegment
export interface SegmentsApi {
/**
* Alias of {@link SegmentsApi.getFlowsTriggeredBySegment}
*
* @deprecated Use {@link SegmentsApi.getFlowsTriggeredBySegment} instead
*/
getSegmentFlowTriggers: typeof SegmentsApi.prototype.getFlowsTriggeredBySegment;
}
SegmentsApi.prototype.getSegmentFlowTriggers = SegmentsApi.prototype.getFlowsTriggeredBySegment
export interface SegmentsApi {
/**
* Alias of {@link SegmentsApi.getIdsForFlowsTriggeredBySegment}
*
* @deprecated Use {@link SegmentsApi.getIdsForFlowsTriggeredBySegment} instead
*/
getFlowTriggerIdsForSegment: typeof SegmentsApi.prototype.getIdsForFlowsTriggeredBySegment;
}
SegmentsApi.prototype.getFlowTriggerIdsForSegment = SegmentsApi.prototype.getIdsForFlowsTriggeredBySegment
export interface SegmentsApi {
/**
* Alias of {@link SegmentsApi.getIdsForFlowsTriggeredBySegment}
*
* @deprecated Use {@link SegmentsApi.getIdsForFlowsTriggeredBySegment} instead
*/
getSegmentRelationshipsFlowTriggers: typeof SegmentsApi.prototype.getIdsForFlowsTriggeredBySegment;
}
SegmentsApi.prototype.getSegmentRelationshipsFlowTriggers = SegmentsApi.prototype.getIdsForFlowsTriggeredBySegment
export interface SegmentsApi {
/**
* Alias of {@link SegmentsApi.getProfileIdsForSegment}
*
* @deprecated Use {@link SegmentsApi.getProfileIdsForSegment} instead
*/
getSegmentRelationshipsProfiles: typeof SegmentsApi.prototype.getProfileIdsForSegment;
}
SegmentsApi.prototype.getSegmentRelationshipsProfiles = SegmentsApi.prototype.getProfileIdsForSegment
export interface SegmentsApi {
/**
* Alias of {@link SegmentsApi.getProfilesForSegment}
*
* @deprecated Use {@link SegmentsApi.getProfilesForSegment} instead
*/
getSegmentProfiles: typeof SegmentsApi.prototype.getProfilesForSegment;
}
SegmentsApi.prototype.getSegmentProfiles = SegmentsApi.prototype.getProfilesForSegment
export interface SegmentsApi {
/**
* Alias of {@link SegmentsApi.getTagIdsForSegment}
*
* @deprecated Use {@link SegmentsApi.getTagIdsForSegment} instead
*/
getSegmentRelationshipsTags: typeof SegmentsApi.prototype.getTagIdsForSegment;
}
SegmentsApi.prototype.getSegmentRelationshipsTags = SegmentsApi.prototype.getTagIdsForSegment
export interface SegmentsApi {
/**
* Alias of {@link SegmentsApi.getTagsForSegment}
*
* @deprecated Use {@link SegmentsApi.getTagsForSegment} instead
*/
getSegmentTags: typeof SegmentsApi.prototype.getTagsForSegment;
}
SegmentsApi.prototype.getSegmentTags = SegmentsApi.prototype.getTagsForSegment