/**
* 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 { GetWebhookResponseCollectionCompoundDocument } from '../model/getWebhookResponseCollectionCompoundDocument';
import { GetWebhookResponseCompoundDocument } from '../model/getWebhookResponseCompoundDocument';
import { GetWebhookTopicResponse } from '../model/getWebhookTopicResponse';
import { GetWebhookTopicResponseCollection } from '../model/getWebhookTopicResponseCollection';
import { PatchWebhookResponse } from '../model/patchWebhookResponse';
import { PostWebhookResponse } from '../model/postWebhookResponse';
import { WebhookCreateQuery } from '../model/webhookCreateQuery';
import { WebhookPartialUpdateQuery } from '../model/webhookPartialUpdateQuery';
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 WebhooksApi {
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 Webhook
*Rate limits*:
Burst: `1/s`
Steady: `15/m` **Scopes:** `webhooks:write`
* @summary Create Webhook
* @param webhookCreateQuery
*/
public async createWebhook (webhookCreateQuery: WebhookCreateQuery, ): Promise<{ response: AxiosResponse; body: PostWebhookResponse; }> {
const localVarPath = this.basePath + '/api/webhooks';
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 'webhookCreateQuery' is not null or undefined
if (webhookCreateQuery === null || webhookCreateQuery === undefined) {
throw new Error('Required parameter webhookCreateQuery was null or undefined when calling createWebhook.');
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'POST',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
data: ObjectSerializer.serialize(webhookCreateQuery, "WebhookCreateQuery")
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: PostWebhookResponse; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "PostWebhookResponse");
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 webhook with the given ID.
*Rate limits*:
Burst: `1/s`
Steady: `15/m` **Scopes:** `webhooks:write`
* @summary Delete Webhook
* @param id The ID of the webhook.
*/
public async deleteWebhook (id: string, ): Promise<{ response: AxiosResponse; body?: any; }> {
const localVarPath = this.basePath + '/api/webhooks/{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 deleteWebhook.');
}
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 the webhook with the given ID.
*Rate limits*:
Burst: `1/s`
Steady: `15/m` **Scopes:** `webhooks:read`
* @summary Get Webhook
* @param id The ID of the webhook.
* @param fieldsWebhook 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 getWebhook (id: string, options: { fieldsWebhook?: Array<'created_at' | 'description' | 'enabled' | 'endpoint_url' | 'name' | 'updated_at'>, include?: Array<'webhook-topics'>, } = {}): Promise<{ response: AxiosResponse; body: GetWebhookResponseCompoundDocument; }> {
const localVarPath = this.basePath + '/api/webhooks/{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 getWebhook.');
}
if (options.fieldsWebhook !== undefined) {
localVarQueryParameters['fields[webhook]'] = ObjectSerializer.serialize(options.fieldsWebhook, "Array<'created_at' | 'description' | 'enabled' | 'endpoint_url' | 'name' | 'updated_at'>");
}
if (options.include !== undefined) {
localVarQueryParameters['include'] = ObjectSerializer.serialize(options.include, "Array<'webhook-topics'>");
}
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: GetWebhookResponseCompoundDocument; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetWebhookResponseCompoundDocument");
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 webhook topic with the given ID.
*Rate limits*:
Burst: `1/s`
Steady: `15/m` **Scopes:** `webhooks:read`
* @summary Get Webhook Topic
* @param id The ID of the webhook topic.
*/
public async getWebhookTopic (id: string, ): Promise<{ response: AxiosResponse; body: GetWebhookTopicResponse; }> {
const localVarPath = this.basePath + '/api/webhook-topics/{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 getWebhookTopic.');
}
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: GetWebhookTopicResponse; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetWebhookTopicResponse");
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 webhook topics in a Klaviyo account.
*Rate limits*:
Burst: `1/s`
Steady: `15/m` **Scopes:** `webhooks:read`
* @summary Get Webhook Topics
*/
public async getWebhookTopics (): Promise<{ response: AxiosResponse; body: GetWebhookTopicResponseCollection; }> {
const localVarPath = this.basePath + '/api/webhook-topics';
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(',');
}
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: GetWebhookTopicResponseCollection; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetWebhookTopicResponseCollection");
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 webhooks in an account.
*Rate limits*:
Burst: `1/s`
Steady: `15/m` **Scopes:** `webhooks:read`
* @summary Get Webhooks
* @param fieldsWebhook 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 getWebhooks (options: { fieldsWebhook?: Array<'created_at' | 'description' | 'enabled' | 'endpoint_url' | 'name' | 'updated_at'>, include?: Array<'webhook-topics'>, } = {}): Promise<{ response: AxiosResponse; body: GetWebhookResponseCollectionCompoundDocument; }> {
const localVarPath = this.basePath + '/api/webhooks';
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.fieldsWebhook !== undefined) {
localVarQueryParameters['fields[webhook]'] = ObjectSerializer.serialize(options.fieldsWebhook, "Array<'created_at' | 'description' | 'enabled' | 'endpoint_url' | 'name' | 'updated_at'>");
}
if (options.include !== undefined) {
localVarQueryParameters['include'] = ObjectSerializer.serialize(options.include, "Array<'webhook-topics'>");
}
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: GetWebhookResponseCollectionCompoundDocument; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "GetWebhookResponseCollectionCompoundDocument");
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 webhook with the given ID.
*Rate limits*:
Burst: `1/s`
Steady: `15/m` **Scopes:** `webhooks:write`
* @summary Update Webhook
* @param id The ID of the webhook.* @param webhookPartialUpdateQuery
*/
public async updateWebhook (id: string, webhookPartialUpdateQuery: WebhookPartialUpdateQuery, ): Promise<{ response: AxiosResponse; body: PatchWebhookResponse; }> {
const localVarPath = this.basePath + '/api/webhooks/{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 updateWebhook.');
}
// verify required parameter 'webhookPartialUpdateQuery' is not null or undefined
if (webhookPartialUpdateQuery === null || webhookPartialUpdateQuery === undefined) {
throw new Error('Required parameter webhookPartialUpdateQuery was null or undefined when calling updateWebhook.');
}
queryParamPreProcessor(localVarQueryParameters)
let config: AxiosRequestConfig = {
method: 'PATCH',
url: localVarPath,
headers: localVarHeaderParams,
params: localVarQueryParameters,
data: ObjectSerializer.serialize(webhookPartialUpdateQuery, "WebhookPartialUpdateQuery")
}
await this.session.applyToRequest(config)
const request = async (config: AxiosRequestConfig, retried = false): Promise<{ response: AxiosResponse; body: PatchWebhookResponse; }> => {
try {
const axiosResponse = await this.session.requestWithRetry(config)
let body;
body = ObjectSerializer.deserialize(axiosResponse.data, "PatchWebhookResponse");
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)
}
}