/** * 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 { CouponCodeCreateJobCreateQuery } from '../model/couponCodeCreateJobCreateQuery'; import { CouponCodeCreateQuery } from '../model/couponCodeCreateQuery'; import { CouponCodeUpdateQuery } from '../model/couponCodeUpdateQuery'; import { CouponCreateQuery } from '../model/couponCreateQuery'; import { CouponUpdateQuery } from '../model/couponUpdateQuery'; import { GetAccounts4XXResponse } from '../model/getAccounts4XXResponse'; import { GetCouponCodeCouponRelationshipResponse } from '../model/getCouponCodeCouponRelationshipResponse'; import { GetCouponCodeCreateJobResponseCollectionCompoundDocument } from '../model/getCouponCodeCreateJobResponseCollectionCompoundDocument'; import { GetCouponCodeCreateJobResponseCompoundDocument } from '../model/getCouponCodeCreateJobResponseCompoundDocument'; import { GetCouponCodeResponseCollection } from '../model/getCouponCodeResponseCollection'; import { GetCouponCodeResponseCollectionCompoundDocument } from '../model/getCouponCodeResponseCollectionCompoundDocument'; import { GetCouponCodeResponseCompoundDocument } from '../model/getCouponCodeResponseCompoundDocument'; import { GetCouponCodesRelationshipsResponseCollection } from '../model/getCouponCodesRelationshipsResponseCollection'; import { GetCouponResponse } from '../model/getCouponResponse'; import { GetCouponResponseCollection } from '../model/getCouponResponseCollection'; import { PatchCouponCodeResponse } from '../model/patchCouponCodeResponse'; import { PatchCouponResponse } from '../model/patchCouponResponse'; import { PostCouponCodeCreateJobResponse } from '../model/postCouponCodeCreateJobResponse'; import { PostCouponCodeResponse } from '../model/postCouponCodeResponse'; import { PostCouponResponse } from '../model/postCouponResponse'; 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 CouponsApi { 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 coupon-code-bulk-create-job to bulk create a list of coupon codes. Max number of coupon codes per job we allow for is 1000. Max number of jobs queued at once we allow for is 100.

*Rate limits*:
Burst: `75/s`
Steady: `750/m` **Scopes:** `coupon-codes:write` * @summary Bulk Create Coupon Codes * @param couponCodeCreateJobCreateQuery */ public async bulkCreateCouponCodes (couponCodeCreateJobCreateQuery: CouponCodeCreateJobCreateQuery, ): Promise<{ response: AxiosResponse; body: PostCouponCodeCreateJobResponse; }> { const localVarPath = this.basePath + '/api/coupon-code-bulk-create-jobs'; 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 'couponCodeCreateJobCreateQuery' is not null or undefined if (couponCodeCreateJobCreateQuery === null || couponCodeCreateJobCreateQuery === undefined) { throw new Error('Required parameter couponCodeCreateJobCreateQuery was null or undefined when calling bulkCreateCouponCodes.'); } queryParamPreProcessor(localVarQueryParameters) let config: AxiosRequestConfig = { method: 'POST', url: localVarPath, headers: localVarHeaderParams, params: localVarQueryParameters, data: ObjectSerializer.serialize(couponCodeCreateJobCreateQuery, "CouponCodeCreateJobCreateQuery") } await this.session.applyToRequest(config) const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: PostCouponCodeCreateJobResponse; }> => { try { const axiosResponse = await this.session.requestWithRetry(config) let body; body = ObjectSerializer.deserialize(axiosResponse.data, "PostCouponCodeCreateJobResponse"); 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) } /** * Creates a new coupon.

*Rate limits*:
Burst: `3/s`
Steady: `60/m` **Scopes:** `coupons:write` * @summary Create Coupon * @param couponCreateQuery */ public async createCoupon (couponCreateQuery: CouponCreateQuery, ): Promise<{ response: AxiosResponse; body: PostCouponResponse; }> { const localVarPath = this.basePath + '/api/coupons'; 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 'couponCreateQuery' is not null or undefined if (couponCreateQuery === null || couponCreateQuery === undefined) { throw new Error('Required parameter couponCreateQuery was null or undefined when calling createCoupon.'); } queryParamPreProcessor(localVarQueryParameters) let config: AxiosRequestConfig = { method: 'POST', url: localVarPath, headers: localVarHeaderParams, params: localVarQueryParameters, data: ObjectSerializer.serialize(couponCreateQuery, "CouponCreateQuery") } await this.session.applyToRequest(config) const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: PostCouponResponse; }> => { try { const axiosResponse = await this.session.requestWithRetry(config) let body; body = ObjectSerializer.deserialize(axiosResponse.data, "PostCouponResponse"); 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) } /** * Synchronously creates a coupon code for the given coupon.

*Rate limits*:
Burst: `350/s`
Steady: `3500/m` **Scopes:** `coupon-codes:write` * @summary Create Coupon Code * @param couponCodeCreateQuery */ public async createCouponCode (couponCodeCreateQuery: CouponCodeCreateQuery, ): Promise<{ response: AxiosResponse; body: PostCouponCodeResponse; }> { const localVarPath = this.basePath + '/api/coupon-codes'; 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 'couponCodeCreateQuery' is not null or undefined if (couponCodeCreateQuery === null || couponCodeCreateQuery === undefined) { throw new Error('Required parameter couponCodeCreateQuery was null or undefined when calling createCouponCode.'); } queryParamPreProcessor(localVarQueryParameters) let config: AxiosRequestConfig = { method: 'POST', url: localVarPath, headers: localVarHeaderParams, params: localVarQueryParameters, data: ObjectSerializer.serialize(couponCodeCreateQuery, "CouponCodeCreateQuery") } await this.session.applyToRequest(config) const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: PostCouponCodeResponse; }> => { try { const axiosResponse = await this.session.requestWithRetry(config) let body; body = ObjectSerializer.deserialize(axiosResponse.data, "PostCouponCodeResponse"); 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 the coupon with the given coupon ID.

*Rate limits*:
Burst: `3/s`
Steady: `60/m` **Scopes:** `coupons:write` * @summary Delete Coupon * @param id The internal id of a Coupon is equivalent to its external id stored within an integration. */ public async deleteCoupon (id: string, ): Promise<{ response: AxiosResponse; body?: any; }> { const localVarPath = this.basePath + '/api/coupons/{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 deleteCoupon.'); } 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) } /** * Deletes a coupon code specified by the given identifier synchronously. If a profile has been assigned to the coupon code, an exception will be raised

*Rate limits*:
Burst: `350/s`
Steady: `3500/m` **Scopes:** `coupon-codes:write` * @summary Delete Coupon Code * @param id The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with. */ public async deleteCouponCode (id: string, ): Promise<{ response: AxiosResponse; body?: any; }> { const localVarPath = this.basePath + '/api/coupon-codes/{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 deleteCouponCode.'); } 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 coupon code bulk create jobs. Returns a maximum of 100 jobs per request.

*Rate limits*:
Burst: `75/s`
Steady: `750/m` **Scopes:** `coupon-codes:read` * @summary Get Bulk Create Coupon Code Jobs * @param fieldsCouponCodeBulkCreateJob 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>`status`: `equals`* @param pageCursor For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#pagination */ public async getBulkCreateCouponCodeJobs (options: { fieldsCouponCodeBulkCreateJob?: Array<'completed_at' | 'completed_count' | 'created_at' | 'errors' | 'expires_at' | 'failed_count' | 'status' | 'total_count'>, filter?: string, pageCursor?: string, } = {}): Promise<{ response: AxiosResponse; body: GetCouponCodeCreateJobResponseCollectionCompoundDocument; }> { const localVarPath = this.basePath + '/api/coupon-code-bulk-create-jobs'; 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.fieldsCouponCodeBulkCreateJob !== undefined) { localVarQueryParameters['fields[coupon-code-bulk-create-job]'] = ObjectSerializer.serialize(options.fieldsCouponCodeBulkCreateJob, "Array<'completed_at' | 'completed_count' | 'created_at' | 'errors' | 'expires_at' | 'failed_count' | 'status' | 'total_count'>"); } if (options.filter !== undefined) { localVarQueryParameters['filter'] = ObjectSerializer.serialize(options.filter, "string"); } 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: GetCouponCodeCreateJobResponseCollectionCompoundDocument; }> => { try { const axiosResponse = await this.session.requestWithRetry(config) let body; body = ObjectSerializer.deserialize(axiosResponse.data, "GetCouponCodeCreateJobResponseCollectionCompoundDocument"); 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 coupon code bulk create job with the given job ID.

*Rate limits*:
Burst: `75/s`
Steady: `750/m` **Scopes:** `coupon-codes:read` * @summary Get Bulk Create Coupon Codes Job * @param jobId ID of the job to retrieve. * @param fieldsCouponCodeBulkCreateJob For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets* @param fieldsCouponCode 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 getBulkCreateCouponCodesJob (jobId: string, options: { fieldsCouponCodeBulkCreateJob?: Array<'completed_at' | 'completed_count' | 'created_at' | 'errors' | 'expires_at' | 'failed_count' | 'status' | 'total_count'>, fieldsCouponCode?: Array<'expires_at' | 'status' | 'unique_code'>, include?: Array<'coupon-codes'>, } = {}): Promise<{ response: AxiosResponse; body: GetCouponCodeCreateJobResponseCompoundDocument; }> { const localVarPath = this.basePath + '/api/coupon-code-bulk-create-jobs/{job_id}' .replace('{' + 'job_id' + '}', encodeURIComponent(String(jobId))); 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 'jobId' is not null or undefined if (jobId === null || jobId === undefined) { throw new Error('Required parameter jobId was null or undefined when calling getBulkCreateCouponCodesJob.'); } if (options.fieldsCouponCodeBulkCreateJob !== undefined) { localVarQueryParameters['fields[coupon-code-bulk-create-job]'] = ObjectSerializer.serialize(options.fieldsCouponCodeBulkCreateJob, "Array<'completed_at' | 'completed_count' | 'created_at' | 'errors' | 'expires_at' | 'failed_count' | 'status' | 'total_count'>"); } if (options.fieldsCouponCode !== undefined) { localVarQueryParameters['fields[coupon-code]'] = ObjectSerializer.serialize(options.fieldsCouponCode, "Array<'expires_at' | 'status' | 'unique_code'>"); } if (options.include !== undefined) { localVarQueryParameters['include'] = ObjectSerializer.serialize(options.include, "Array<'coupon-codes'>"); } 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: GetCouponCodeCreateJobResponseCompoundDocument; }> => { try { const axiosResponse = await this.session.requestWithRetry(config) let body; body = ObjectSerializer.deserialize(axiosResponse.data, "GetCouponCodeCreateJobResponseCompoundDocument"); 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 specific coupon with the given coupon ID.

*Rate limits*:
Burst: `75/s`
Steady: `750/m` **Scopes:** `coupons:read` * @summary Get Coupon * @param id The internal id of a Coupon is equivalent to its external id stored within an integration. * @param fieldsCoupon For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets */ public async getCoupon (id: string, options: { fieldsCoupon?: Array<'description' | 'external_id' | 'monitor_configuration'>, } = {}): Promise<{ response: AxiosResponse; body: GetCouponResponse; }> { const localVarPath = this.basePath + '/api/coupons/{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 getCoupon.'); } if (options.fieldsCoupon !== undefined) { localVarQueryParameters['fields[coupon]'] = ObjectSerializer.serialize(options.fieldsCoupon, "Array<'description' | 'external_id' | 'monitor_configuration'>"); } 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: GetCouponResponse; }> => { try { const axiosResponse = await this.session.requestWithRetry(config) let body; body = ObjectSerializer.deserialize(axiosResponse.data, "GetCouponResponse"); 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) } /** * Returns a Coupon Code specified by the given identifier.

*Rate limits*:
Burst: `350/s`
Steady: `3500/m` **Scopes:** `coupon-codes:read` * @summary Get Coupon Code * @param id The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with. * @param fieldsCouponCode For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets* @param fieldsCoupon 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 getCouponCode (id: string, options: { fieldsCouponCode?: Array<'expires_at' | 'status' | 'unique_code'>, fieldsCoupon?: Array<'description' | 'external_id' | 'monitor_configuration'>, include?: Array<'coupon'>, } = {}): Promise<{ response: AxiosResponse; body: GetCouponCodeResponseCompoundDocument; }> { const localVarPath = this.basePath + '/api/coupon-codes/{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 getCouponCode.'); } if (options.fieldsCouponCode !== undefined) { localVarQueryParameters['fields[coupon-code]'] = ObjectSerializer.serialize(options.fieldsCouponCode, "Array<'expires_at' | 'status' | 'unique_code'>"); } if (options.fieldsCoupon !== undefined) { localVarQueryParameters['fields[coupon]'] = ObjectSerializer.serialize(options.fieldsCoupon, "Array<'description' | 'external_id' | 'monitor_configuration'>"); } if (options.include !== undefined) { localVarQueryParameters['include'] = ObjectSerializer.serialize(options.include, "Array<'coupon'>"); } 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: GetCouponCodeResponseCompoundDocument; }> => { try { const axiosResponse = await this.session.requestWithRetry(config) let body; body = ObjectSerializer.deserialize(axiosResponse.data, "GetCouponCodeResponseCompoundDocument"); 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) } /** * Gets a list of coupon code relationships associated with the given coupon id

*Rate limits*:
Burst: `75/s`
Steady: `750/m` **Scopes:** `coupon-codes:read` * @summary Get Coupon Code IDs for Coupon * @param id The ID of the coupon to look up the relationship of. * @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>`expires_at`: `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than`<br>`status`: `equals`<br>`coupon.id`: `any`, `equals`<br>`profile.id`: `any`, `equals`* @param pageCursor For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#pagination */ public async getCouponCodeIdsForCoupon (id: string, options: { filter?: string, pageCursor?: string, } = {}): Promise<{ response: AxiosResponse; body: GetCouponCodesRelationshipsResponseCollection; }> { const localVarPath = this.basePath + '/api/coupons/{id}/relationships/coupon-codes' .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 getCouponCodeIdsForCoupon.'); } if (options.filter !== undefined) { localVarQueryParameters['filter'] = ObjectSerializer.serialize(options.filter, "string"); } 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: GetCouponCodesRelationshipsResponseCollection; }> => { try { const axiosResponse = await this.session.requestWithRetry(config) let body; body = ObjectSerializer.deserialize(axiosResponse.data, "GetCouponCodesRelationshipsResponseCollection"); 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) } /** * Gets a list of coupon codes associated with a coupon/coupons or a profile/profiles. A coupon/coupons or a profile/profiles must be provided as required filter params.

*Rate limits*:
Burst: `350/s`
Steady: `3500/m` **Scopes:** `coupon-codes:read` * @summary Get Coupon Codes * @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>`expires_at`: `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than`<br>`status`: `equals`<br>`coupon.id`: `any`, `equals`<br>`profile.id`: `any`, `equals` * @param fieldsCouponCode For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets* @param fieldsCoupon 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* @param pageCursor For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#pagination */ public async getCouponCodes (filter: string, options: { fieldsCouponCode?: Array<'expires_at' | 'status' | 'unique_code'>, fieldsCoupon?: Array<'description' | 'external_id' | 'monitor_configuration'>, include?: Array<'coupon'>, pageCursor?: string, } = {}): Promise<{ response: AxiosResponse; body: GetCouponCodeResponseCollectionCompoundDocument; }> { const localVarPath = this.basePath + '/api/coupon-codes'; 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 'filter' is not null or undefined if (filter === null || filter === undefined) { throw new Error('Required parameter filter was null or undefined when calling getCouponCodes.'); } if (options.fieldsCouponCode !== undefined) { localVarQueryParameters['fields[coupon-code]'] = ObjectSerializer.serialize(options.fieldsCouponCode, "Array<'expires_at' | 'status' | 'unique_code'>"); } if (options.fieldsCoupon !== undefined) { localVarQueryParameters['fields[coupon]'] = ObjectSerializer.serialize(options.fieldsCoupon, "Array<'description' | 'external_id' | 'monitor_configuration'>"); } localVarQueryParameters['filter'] = ObjectSerializer.serialize(filter, "string"); if (options.include !== undefined) { localVarQueryParameters['include'] = ObjectSerializer.serialize(options.include, "Array<'coupon'>"); } 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: GetCouponCodeResponseCollectionCompoundDocument; }> => { try { const axiosResponse = await this.session.requestWithRetry(config) let body; body = ObjectSerializer.deserialize(axiosResponse.data, "GetCouponCodeResponseCollectionCompoundDocument"); 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) } /** * Gets a list of coupon codes associated with the given coupon id

*Rate limits*:
Burst: `75/s`
Steady: `750/m` **Scopes:** `coupon-codes:read` * @summary Get Coupon Codes for Coupon * @param id The ID of the coupon to look up the relationship of. * @param fieldsCouponCode 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>`expires_at`: `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than`<br>`status`: `equals`<br>`coupon.id`: `any`, `equals`<br>`profile.id`: `any`, `equals`* @param pageCursor For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#pagination */ public async getCouponCodesForCoupon (id: string, options: { fieldsCouponCode?: Array<'expires_at' | 'status' | 'unique_code'>, filter?: string, pageCursor?: string, } = {}): Promise<{ response: AxiosResponse; body: GetCouponCodeResponseCollection; }> { const localVarPath = this.basePath + '/api/coupons/{id}/coupon-codes' .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 getCouponCodesForCoupon.'); } if (options.fieldsCouponCode !== undefined) { localVarQueryParameters['fields[coupon-code]'] = ObjectSerializer.serialize(options.fieldsCouponCode, "Array<'expires_at' | 'status' | 'unique_code'>"); } if (options.filter !== undefined) { localVarQueryParameters['filter'] = ObjectSerializer.serialize(options.filter, "string"); } 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: GetCouponCodeResponseCollection; }> => { try { const axiosResponse = await this.session.requestWithRetry(config) let body; body = ObjectSerializer.deserialize(axiosResponse.data, "GetCouponCodeResponseCollection"); 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 coupon associated with a given coupon code ID.

*Rate limits*:
Burst: `75/s`
Steady: `750/m` **Scopes:** `coupons:read` * @summary Get Coupon For Coupon Code * @param id The ID of the coupon to look up the relationship of. * @param fieldsCoupon For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets */ public async getCouponForCouponCode (id: string, options: { fieldsCoupon?: Array<'description' | 'external_id' | 'monitor_configuration'>, } = {}): Promise<{ response: AxiosResponse; body: GetCouponResponse; }> { const localVarPath = this.basePath + '/api/coupon-codes/{id}/coupon' .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 getCouponForCouponCode.'); } if (options.fieldsCoupon !== undefined) { localVarQueryParameters['fields[coupon]'] = ObjectSerializer.serialize(options.fieldsCoupon, "Array<'description' | 'external_id' | 'monitor_configuration'>"); } 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: GetCouponResponse; }> => { try { const axiosResponse = await this.session.requestWithRetry(config) let body; body = ObjectSerializer.deserialize(axiosResponse.data, "GetCouponResponse"); 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) } /** * Gets the coupon relationship associated with the given coupon code id

*Rate limits*:
Burst: `75/s`
Steady: `750/m` **Scopes:** `coupons:read` * @summary Get Coupon ID for Coupon Code * @param id The ID of the coupon to look up the relationship of. */ public async getCouponIdForCouponCode (id: string, ): Promise<{ response: AxiosResponse; body: GetCouponCodeCouponRelationshipResponse; }> { const localVarPath = this.basePath + '/api/coupon-codes/{id}/relationships/coupon' .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 getCouponIdForCouponCode.'); } 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: GetCouponCodeCouponRelationshipResponse; }> => { try { const axiosResponse = await this.session.requestWithRetry(config) let body; body = ObjectSerializer.deserialize(axiosResponse.data, "GetCouponCodeCouponRelationshipResponse"); 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 coupons in an account. To learn more, see our [Coupons API guide](https://developers.klaviyo.com/en/docs/use_klaviyos_coupons_api).

*Rate limits*:
Burst: `75/s`
Steady: `750/m` **Scopes:** `coupons:read` * @summary Get Coupons * @param fieldsCoupon For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#sparse-fieldsets* @param pageCursor For more information please visit https://developers.klaviyo.com/en/v2026-04-15/reference/api-overview#pagination */ public async getCoupons (options: { fieldsCoupon?: Array<'description' | 'external_id' | 'monitor_configuration'>, pageCursor?: string, } = {}): Promise<{ response: AxiosResponse; body: GetCouponResponseCollection; }> { const localVarPath = this.basePath + '/api/coupons'; 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.fieldsCoupon !== undefined) { localVarQueryParameters['fields[coupon]'] = ObjectSerializer.serialize(options.fieldsCoupon, "Array<'description' | 'external_id' | 'monitor_configuration'>"); } 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: GetCouponResponseCollection; }> => { try { const axiosResponse = await this.session.requestWithRetry(config) let body; body = ObjectSerializer.deserialize(axiosResponse.data, "GetCouponResponseCollection"); 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) } /** * *Rate limits*:
Burst: `3/s`
Steady: `60/m` **Scopes:** `coupons:write` * @summary Update Coupon * @param id The internal id of a Coupon is equivalent to its external id stored within an integration.* @param couponUpdateQuery */ public async updateCoupon (id: string, couponUpdateQuery: CouponUpdateQuery, ): Promise<{ response: AxiosResponse; body: PatchCouponResponse; }> { const localVarPath = this.basePath + '/api/coupons/{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 updateCoupon.'); } // verify required parameter 'couponUpdateQuery' is not null or undefined if (couponUpdateQuery === null || couponUpdateQuery === undefined) { throw new Error('Required parameter couponUpdateQuery was null or undefined when calling updateCoupon.'); } queryParamPreProcessor(localVarQueryParameters) let config: AxiosRequestConfig = { method: 'PATCH', url: localVarPath, headers: localVarHeaderParams, params: localVarQueryParameters, data: ObjectSerializer.serialize(couponUpdateQuery, "CouponUpdateQuery") } await this.session.applyToRequest(config) const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: PatchCouponResponse; }> => { try { const axiosResponse = await this.session.requestWithRetry(config) let body; body = ObjectSerializer.deserialize(axiosResponse.data, "PatchCouponResponse"); 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) } /** * Updates a coupon code specified by the given identifier synchronously. We allow updating the \'status\' and \'expires_at\' of coupon codes.

*Rate limits*:
Burst: `350/s`
Steady: `3500/m` **Scopes:** `coupon-codes:write` * @summary Update Coupon Code * @param id The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with.* @param couponCodeUpdateQuery */ public async updateCouponCode (id: string, couponCodeUpdateQuery: CouponCodeUpdateQuery, ): Promise<{ response: AxiosResponse; body: PatchCouponCodeResponse; }> { const localVarPath = this.basePath + '/api/coupon-codes/{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 updateCouponCode.'); } // verify required parameter 'couponCodeUpdateQuery' is not null or undefined if (couponCodeUpdateQuery === null || couponCodeUpdateQuery === undefined) { throw new Error('Required parameter couponCodeUpdateQuery was null or undefined when calling updateCouponCode.'); } queryParamPreProcessor(localVarQueryParameters) let config: AxiosRequestConfig = { method: 'PATCH', url: localVarPath, headers: localVarHeaderParams, params: localVarQueryParameters, data: ObjectSerializer.serialize(couponCodeUpdateQuery, "CouponCodeUpdateQuery") } await this.session.applyToRequest(config) const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: PatchCouponCodeResponse; }> => { try { const axiosResponse = await this.session.requestWithRetry(config) let body; body = ObjectSerializer.deserialize(axiosResponse.data, "PatchCouponCodeResponse"); 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 CouponsApi { /** * Alias of {@link CouponsApi.bulkCreateCouponCodes} * * @deprecated Use {@link CouponsApi.bulkCreateCouponCodes} instead */ spawnCouponCodeBulkCreateJob: typeof CouponsApi.prototype.bulkCreateCouponCodes; } CouponsApi.prototype.spawnCouponCodeBulkCreateJob = CouponsApi.prototype.bulkCreateCouponCodes export interface CouponsApi { /** * Alias of {@link CouponsApi.bulkCreateCouponCodes} * * @deprecated Use {@link CouponsApi.bulkCreateCouponCodes} instead */ createCouponCodeBulkCreateJob: typeof CouponsApi.prototype.bulkCreateCouponCodes; } CouponsApi.prototype.createCouponCodeBulkCreateJob = CouponsApi.prototype.bulkCreateCouponCodes export interface CouponsApi { /** * Alias of {@link CouponsApi.getBulkCreateCouponCodeJobs} * * @deprecated Use {@link CouponsApi.getBulkCreateCouponCodeJobs} instead */ getCouponCodeBulkCreateJobs: typeof CouponsApi.prototype.getBulkCreateCouponCodeJobs; } CouponsApi.prototype.getCouponCodeBulkCreateJobs = CouponsApi.prototype.getBulkCreateCouponCodeJobs export interface CouponsApi { /** * Alias of {@link CouponsApi.getBulkCreateCouponCodesJob} * * @deprecated Use {@link CouponsApi.getBulkCreateCouponCodesJob} instead */ getCouponCodeBulkCreateJob: typeof CouponsApi.prototype.getBulkCreateCouponCodesJob; } CouponsApi.prototype.getCouponCodeBulkCreateJob = CouponsApi.prototype.getBulkCreateCouponCodesJob export interface CouponsApi { /** * Alias of {@link CouponsApi.getCouponCodeIdsForCoupon} * * @deprecated Use {@link CouponsApi.getCouponCodeIdsForCoupon} instead */ getCouponCodeRelationshipsCoupon: typeof CouponsApi.prototype.getCouponCodeIdsForCoupon; } CouponsApi.prototype.getCouponCodeRelationshipsCoupon = CouponsApi.prototype.getCouponCodeIdsForCoupon export interface CouponsApi { /** * Alias of {@link CouponsApi.getCouponCodeIdsForCoupon} * * @deprecated Use {@link CouponsApi.getCouponCodeIdsForCoupon} instead */ getCodeIdsForCoupon: typeof CouponsApi.prototype.getCouponCodeIdsForCoupon; } CouponsApi.prototype.getCodeIdsForCoupon = CouponsApi.prototype.getCouponCodeIdsForCoupon export interface CouponsApi { /** * Alias of {@link CouponsApi.getCouponCodeIdsForCoupon} * * @deprecated Use {@link CouponsApi.getCouponCodeIdsForCoupon} instead */ getCouponRelationshipsCodes: typeof CouponsApi.prototype.getCouponCodeIdsForCoupon; } CouponsApi.prototype.getCouponRelationshipsCodes = CouponsApi.prototype.getCouponCodeIdsForCoupon export interface CouponsApi { /** * Alias of {@link CouponsApi.getCouponCodesForCoupon} * * @deprecated Use {@link CouponsApi.getCouponCodesForCoupon} instead */ getCouponCouponCodes: typeof CouponsApi.prototype.getCouponCodesForCoupon; } CouponsApi.prototype.getCouponCouponCodes = CouponsApi.prototype.getCouponCodesForCoupon export interface CouponsApi { /** * Alias of {@link CouponsApi.getCouponCodesForCoupon} * * @deprecated Use {@link CouponsApi.getCouponCodesForCoupon} instead */ getCodesForCoupon: typeof CouponsApi.prototype.getCouponCodesForCoupon; } CouponsApi.prototype.getCodesForCoupon = CouponsApi.prototype.getCouponCodesForCoupon export interface CouponsApi { /** * Alias of {@link CouponsApi.getCouponForCouponCode} * * @deprecated Use {@link CouponsApi.getCouponForCouponCode} instead */ getCouponCodeCoupon: typeof CouponsApi.prototype.getCouponForCouponCode; } CouponsApi.prototype.getCouponCodeCoupon = CouponsApi.prototype.getCouponForCouponCode export interface CouponsApi { /** * Alias of {@link CouponsApi.getCouponIdForCouponCode} * * @deprecated Use {@link CouponsApi.getCouponIdForCouponCode} instead */ getCouponRelationshipsCouponCodes: typeof CouponsApi.prototype.getCouponIdForCouponCode; } CouponsApi.prototype.getCouponRelationshipsCouponCodes = CouponsApi.prototype.getCouponIdForCouponCode