UNPKG

klaviyo-api-fetch

Version:

A native fetch API using hey-api ts codegen

1,521 lines (1,514 loc) 1.37 MB
type AuthToken = string | undefined; interface Auth { /** * Which part of the request do we use to send the auth? * * @default 'header' */ in?: 'header' | 'query' | 'cookie'; /** * Header or query parameter name. * * @default 'Authorization' */ name?: string; scheme?: 'basic' | 'bearer'; type: 'apiKey' | 'http'; } interface SerializerOptions<T> { /** * @default true */ explode: boolean; style: T; } type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited'; type ObjectStyle = 'form' | 'deepObject'; type QuerySerializer = (query: Record<string, unknown>) => string; type BodySerializer = (body: any) => any; type QuerySerializerOptionsObject = { allowReserved?: boolean; array?: Partial<SerializerOptions<ArrayStyle>>; object?: Partial<SerializerOptions<ObjectStyle>>; }; type QuerySerializerOptions = QuerySerializerOptionsObject & { /** * Per-parameter serialization overrides. When provided, these settings * override the global array/object settings for specific parameter names. */ parameters?: Record<string, QuerySerializerOptionsObject>; }; type HttpMethod = 'connect' | 'delete' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put' | 'trace'; type Client$1<RequestFn = never, Config = unknown, MethodFn = never, BuildUrlFn = never, SseFn = never> = { /** * Returns the final request URL. */ buildUrl: BuildUrlFn; getConfig: () => Config; request: RequestFn; setConfig: (config: Config) => Config; } & { [K in HttpMethod]: MethodFn; } & ([SseFn] extends [never] ? { sse?: never; } : { sse: { [K in HttpMethod]: SseFn; }; }); interface Config$1 { /** * Auth token or a function returning auth token. The resolved value will be * added to the request payload as defined by its `security` array. */ auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken; /** * A function for serializing request body parameter. By default, * {@link JSON.stringify()} will be used. */ bodySerializer?: BodySerializer | null; /** * An object containing any HTTP headers that you want to pre-populate your * `Headers` object with. * * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more} */ headers?: RequestInit['headers'] | Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined | unknown>; /** * The request method. * * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more} */ method?: Uppercase<HttpMethod>; /** * A function for serializing request query parameters. By default, arrays * will be exploded in form style, objects will be exploded in deepObject * style, and reserved characters are percent-encoded. * * This method will have no effect if the native `paramsSerializer()` Axios * API function is used. * * {@link https://swagger.io/docs/specification/serialization/#query View examples} */ querySerializer?: QuerySerializer | QuerySerializerOptions; /** * A function validating request data. This is useful if you want to ensure * the request conforms to the desired shape, so it can be safely sent to * the server. */ requestValidator?: (data: unknown) => Promise<unknown>; /** * A function transforming response data before it's returned. This is useful * for post-processing data, e.g. converting ISO strings into Date objects. */ responseTransformer?: (data: unknown) => Promise<unknown>; /** * A function validating response data. This is useful if you want to ensure * the response conforms to the desired shape, so it can be safely passed to * the transformers and returned to the user. */ responseValidator?: (data: unknown) => Promise<unknown>; } type ServerSentEventsOptions<TData = unknown> = Omit<RequestInit, 'method'> & Pick<Config$1, 'method' | 'responseTransformer' | 'responseValidator'> & { /** * Fetch API implementation. You can use this option to provide a custom * fetch instance. * * @default globalThis.fetch */ fetch?: typeof fetch; /** * Implementing clients can call request interceptors inside this hook. */ onRequest?: (url: string, init: RequestInit) => Promise<Request>; /** * Callback invoked when a network or parsing error occurs during streaming. * * This option applies only if the endpoint returns a stream of events. * * @param error The error that occurred. */ onSseError?: (error: unknown) => void; /** * Callback invoked when an event is streamed from the server. * * This option applies only if the endpoint returns a stream of events. * * @param event Event streamed from the server. * @returns Nothing (void). */ onSseEvent?: (event: StreamEvent<TData>) => void; serializedBody?: RequestInit['body']; /** * Default retry delay in milliseconds. * * This option applies only if the endpoint returns a stream of events. * * @default 3000 */ sseDefaultRetryDelay?: number; /** * Maximum number of retry attempts before giving up. */ sseMaxRetryAttempts?: number; /** * Maximum retry delay in milliseconds. * * Applies only when exponential backoff is used. * * This option applies only if the endpoint returns a stream of events. * * @default 30000 */ sseMaxRetryDelay?: number; /** * Optional sleep function for retry backoff. * * Defaults to using `setTimeout`. */ sseSleepFn?: (ms: number) => Promise<void>; url: string; }; interface StreamEvent<TData = unknown> { data: TData; event?: string; id?: string; retry?: number; } type ServerSentEventsResult<TData = unknown, TReturn = void, TNext = unknown> = { stream: AsyncGenerator<TData extends Record<string, unknown> ? TData[keyof TData] : TData, TReturn, TNext>; }; type ErrInterceptor<Err, Res, Req, Options> = (error: Err, response: Res, request: Req, options: Options) => Err | Promise<Err>; type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>; type ResInterceptor<Res, Req, Options> = (response: Res, request: Req, options: Options) => Res | Promise<Res>; declare class Interceptors<Interceptor> { fns: Array<Interceptor | null>; clear(): void; eject(id: number | Interceptor): void; exists(id: number | Interceptor): boolean; getInterceptorIndex(id: number | Interceptor): number; update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false; use(fn: Interceptor): number; } interface Middleware<Req, Res, Err, Options> { error: Interceptors<ErrInterceptor<Err, Res, Req, Options>>; request: Interceptors<ReqInterceptor<Req, Options>>; response: Interceptors<ResInterceptor<Res, Req, Options>>; } type ResponseStyle = 'data' | 'fields'; interface Config<T extends ClientOptions$1 = ClientOptions$1> extends Omit<RequestInit, 'body' | 'headers' | 'method'>, Config$1 { /** * Base URL for all requests made by this client. */ baseUrl?: T['baseUrl']; /** * Fetch API implementation. You can use this option to provide a custom * fetch instance. * * @default globalThis.fetch */ fetch?: typeof fetch; /** * Please don't use the Fetch client for Next.js applications. The `next` * options won't have any effect. * * Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead. */ next?: never; /** * Return the response data parsed in a specified format. By default, `auto` * will infer the appropriate method from the `Content-Type` response header. * You can override this behavior with any of the {@link Body} methods. * Select `stream` if you don't want to parse response data at all. * * @default 'auto' */ parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text'; /** * Should we return only data or multiple fields (data, error, response, etc.)? * * @default 'fields' */ responseStyle?: ResponseStyle; /** * Throw an error instead of returning it in the response? * * @default false */ throwOnError?: T['throwOnError']; } interface RequestOptions<TData = unknown, TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{ responseStyle: TResponseStyle; throwOnError: ThrowOnError; }>, Pick<ServerSentEventsOptions<TData>, 'onSseError' | 'onSseEvent' | 'sseDefaultRetryDelay' | 'sseMaxRetryAttempts' | 'sseMaxRetryDelay'> { /** * Any body that you want to add to your request. * * {@link https://developer.mozilla.org/docs/Web/API/fetch#body} */ body?: unknown; path?: Record<string, unknown>; query?: Record<string, unknown>; /** * Security mechanism(s) to use for the request. */ security?: ReadonlyArray<Auth>; url: Url; } interface ResolvedRequestOptions<TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> { serializedBody?: string; } type RequestResult<TData = unknown, TError = unknown, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle = 'fields'> = ThrowOnError extends true ? Promise<TResponseStyle extends 'data' ? TData extends Record<string, unknown> ? TData[keyof TData] : TData : { data: TData extends Record<string, unknown> ? TData[keyof TData] : TData; request: Request; response: Response; }> : Promise<TResponseStyle extends 'data' ? (TData extends Record<string, unknown> ? TData[keyof TData] : TData) | undefined : ({ data: TData extends Record<string, unknown> ? TData[keyof TData] : TData; error: undefined; } | { data: undefined; error: TError extends Record<string, unknown> ? TError[keyof TError] : TError; }) & { request: Request; response: Response; }>; interface ClientOptions$1 { baseUrl?: string; responseStyle?: ResponseStyle; throwOnError?: boolean; } type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>; type SseFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>) => Promise<ServerSentEventsResult<TData, TError>>; type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = 'fields'>(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'> & Pick<Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>, 'method'>) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>; type BuildUrlFn = <TData extends { body?: unknown; path?: Record<string, unknown>; query?: Record<string, unknown>; url: string; }>(options: TData & Options$1<TData>) => string; type Client = Client$1<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & { interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>; }; interface TDataShape { body?: unknown; headers?: unknown; path?: unknown; query?: unknown; url: string; } type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>; type Options$1<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown, TResponseStyle extends ResponseStyle = 'fields'> = OmitKeys<RequestOptions<TResponse, TResponseStyle, ThrowOnError>, 'body' | 'path' | 'query' | 'url'> & ([TData] extends [never] ? unknown : Omit<TData, 'url'>); type ClientOptions = { baseUrl: 'https://a.klaviyo.com' | (string & {}); }; type CouponEnum = 'coupon'; type CouponResponseObjectResource = { type: CouponEnum; /** * The internal id of a Coupon is equivalent to its external id stored within an integration. */ id: string; attributes: { /** * This is the id that is stored in an integration such as Shopify or Magento. */ external_id: string; /** * A description of the coupon. */ description?: string | null; /** * The monitor configuration for the coupon. */ monitor_configuration?: { [key: string]: unknown; } | null; }; links: ObjectLinks; }; type GetCouponResponseCollection = { data: Array<CouponResponseObjectResource>; links?: CollectionLinks; }; type GetCouponResponse = { data: CouponResponseObjectResource; links?: ObjectLinks; }; type GetCouponCodeCouponRelationshipResponse = { data: { type: CouponEnum; /** * The internal id of a Coupon is equivalent to its external id stored within an integration. */ id: string; }; links?: ObjectLinks; }; type CouponCodeEnum = 'coupon-code'; type CouponCodeResponseObjectResource = { type: CouponCodeEnum; /** * The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with. */ id: string; attributes: { /** * This is a unique string that will be or is assigned to each customer/profile and is associated with a coupon. */ unique_code?: string | null; /** * The datetime when this coupon code will expire. If not specified or set to null, it will be automatically set to 1 year. */ expires_at?: string | null; /** * The current status of the coupon code. */ status?: 'ASSIGNED_TO_PROFILE' | 'DELETING' | 'PROCESSING' | 'UNASSIGNED' | 'USED' | 'VERSION_NOT_ACTIVE'; }; links: ObjectLinks; }; type GetCouponCodeResponseCollectionCompoundDocument = { data: Array<CouponCodeResponseObjectResource & { relationships?: { coupon?: { data?: { type: CouponEnum; id: string; }; links?: RelationshipLinks; }; profile?: { links?: RelationshipLinks; }; }; }>; links?: CollectionLinks; included?: Array<CouponResponseObjectResource>; }; type GetCouponCodeResponseCompoundDocument = { data: CouponCodeResponseObjectResource & { relationships?: { coupon?: { data?: { type: CouponEnum; id: string; }; links?: RelationshipLinks; }; profile?: { links?: RelationshipLinks; }; }; }; included?: Array<CouponResponseObjectResource>; links?: ObjectLinks; }; type GetCouponCodeResponseCollection = { data: Array<CouponCodeResponseObjectResource & { relationships?: { coupon?: { links?: RelationshipLinks; }; profile?: { links?: RelationshipLinks; }; }; }>; links?: CollectionLinks; }; type GetCouponCodesRelationshipsResponseCollection = { data: Array<{ type: CouponCodeEnum; /** * The id of a coupon code is a combination of its unique code and the id of the coupon it is associated with. */ id: string; }>; links?: CollectionLinks; }; type CatalogItemEnum = 'catalog-item'; type CatalogVariantEnum = 'catalog-variant'; type CatalogVariantResponseObjectResource = { type: CatalogVariantEnum; /** * The catalog variant ID is a compound ID (string), with format: `{integration}:::{catalog}:::{external_id}`. Currently, the only supported integration type is `$custom`, and the only supported catalog is `$default`. */ id: string; attributes: { /** * The ID of the catalog item variant in an external system. */ external_id?: string | null; /** * The title of the catalog item variant. */ title?: string | null; /** * A description of the catalog item variant. */ description?: string | null; /** * The SKU of the catalog item variant. */ sku?: string | null; /** * This field controls the visibility of this catalog item variant in product feeds/blocks. This field supports the following values: * `1`: a product will not appear in dynamic product recommendation feeds and blocks if it is out of stock. * `0` or `2`: a product can appear in dynamic product recommendation feeds and blocks regardless of inventory quantity. */ inventory_policy?: 0 | 1 | 2; /** * The quantity of the catalog item variant currently in stock. */ inventory_quantity?: number | null; /** * This field can be used to set the price on the catalog item variant, which is what gets displayed for the item variant when included in emails. For most price-update use cases, you will also want to update the `price` on any parent items using the [Update Catalog Item Endpoint](https://developers.klaviyo.com/en/reference/update_catalog_item). */ price?: number | null; /** * URL pointing to the location of the catalog item variant on your website. */ url?: string | null; /** * URL pointing to the location of a full image of the catalog item variant. */ image_full_url?: string | null; /** * URL pointing to the location of an image thumbnail of the catalog item variant. */ image_thumbnail_url?: string | null; /** * List of URLs pointing to the locations of images of the catalog item variant. */ images?: Array<string> | null; /** * Flat JSON blob to provide custom metadata about the catalog item variant. May not exceed 100kb. */ custom_metadata?: { [key: string]: unknown; } | null; /** * Boolean value indicating whether the catalog item variant is published. */ published?: boolean | null; /** * Date and time when the catalog item variant was created, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ created?: string | null; /** * Date and time when the catalog item variant was last updated, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ updated?: string | null; }; links: ObjectLinks; }; type CatalogItemResponseObjectResource = { type: CatalogItemEnum; /** * The catalog item ID is a compound ID (string), with format: `{integration}:::{catalog}:::{external_id}`. Currently, the only supported integration type is `$custom`, and the only supported catalog is `$default`. */ id: string; attributes: { /** * The ID of the catalog item in an external system. */ external_id?: string | null; /** * The title of the catalog item. */ title?: string | null; /** * A description of the catalog item. */ description?: string | null; /** * This field can be used to set the price on the catalog item, which is what gets displayed for the item when included in emails. For most price-update use cases, you will also want to update the `price` on any child variants, using the [Update Catalog Variant Endpoint](https://developers.klaviyo.com/en/reference/update_catalog_variant). */ price?: number | null; /** * URL pointing to the location of the catalog item on your website. */ url?: string | null; /** * URL pointing to the location of a full image of the catalog item. */ image_full_url?: string | null; /** * URL pointing to the location of an image thumbnail of the catalog item */ image_thumbnail_url?: string | null; /** * List of URLs pointing to the locations of images of the catalog item. */ images?: Array<string> | null; /** * Flat JSON blob to provide custom metadata about the catalog item. May not exceed 100kb. */ custom_metadata?: { [key: string]: unknown; } | null; /** * Boolean value indicating whether the catalog item is published. */ published?: boolean | null; /** * Date and time when the catalog item was created, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ created?: string | null; /** * Date and time when the catalog item was last updated, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ updated?: string | null; }; links: ObjectLinks; }; type GetCatalogItemResponseCollectionCompoundDocument = { data: Array<CatalogItemResponseObjectResource & { relationships?: { variants?: { data?: Array<{ type: CatalogVariantEnum; id: string; }>; links?: RelationshipLinks; }; }; }>; links?: CollectionLinks; included?: Array<CatalogVariantResponseObjectResource>; }; type GetCatalogItemResponseCompoundDocument = { data: CatalogItemResponseObjectResource & { relationships?: { variants?: { data?: Array<{ type: CatalogVariantEnum; id: string; }>; links?: RelationshipLinks; }; }; }; included?: Array<CatalogVariantResponseObjectResource>; links?: ObjectLinks; }; type GetCatalogCategoryItemsRelationshipsResponseCollection = { data: Array<{ type: CatalogItemEnum; /** * The catalog item ID is a compound ID (string), with format: `{integration}:::{catalog}:::{external_id}`. Currently, the only supported integration type is `$custom`, and the only supported catalog is `$default`. */ id: string; }>; links?: CollectionLinks; }; type GetCatalogVariantResponseCollection = { data: Array<CatalogVariantResponseObjectResource & { relationships?: { item?: { links?: RelationshipLinks; }; }; }>; links?: CollectionLinks; }; type GetCatalogVariantResponse = { data: CatalogVariantResponseObjectResource & { relationships?: { item?: { links?: RelationshipLinks; }; }; }; links?: ObjectLinks; }; type GetCatalogItemVariantsRelationshipsResponseCollection = { data: Array<{ type: CatalogVariantEnum; /** * The catalog variant ID is a compound ID (string), with format: `{integration}:::{catalog}:::{external_id}`. Currently, the only supported integration type is `$custom`, and the only supported catalog is `$default`. */ id: string; }>; links?: CollectionLinks; }; type CatalogCategoryEnum = 'catalog-category'; type CatalogCategoryResponseObjectResource = { type: CatalogCategoryEnum; /** * The catalog category ID is a compound ID (string), with format: `{integration}:::{catalog}:::{external_id}`. Currently, the only supported integration type is `$custom`, and the only supported catalog is `$default`. */ id: string; attributes: { /** * The ID of the catalog category in an external system. */ external_id?: string | null; /** * The name of the catalog category. */ name?: string | null; /** * Date and time when the catalog category was last updated, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ updated?: string | null; }; links: ObjectLinks; }; type GetCatalogCategoryResponseCollection = { data: Array<CatalogCategoryResponseObjectResource & { relationships?: { items?: { links?: RelationshipLinks; }; }; }>; links?: CollectionLinks; }; type GetCatalogCategoryResponse = { data: CatalogCategoryResponseObjectResource & { relationships?: { items?: { links?: RelationshipLinks; }; }; }; links?: ObjectLinks; }; type ErrorSource = { /** * A pointer to the source of the error in the request payload. */ pointer?: string | null; }; type ApiJobErrorPayload = { /** * Unique identifier for the error. */ id: string; /** * A code for classifying the error type. */ code: string; /** * A high-level message about the error. */ title: string; /** * Specific details about the error. */ detail: string; source: ErrorSource; }; type CouponCodeBulkCreateJobEnum = 'coupon-code-bulk-create-job'; type CouponCodeCreateJobResponseObjectResource = { type: CouponCodeBulkCreateJobEnum; /** * Unique identifier for retrieving the job. Generated by Klaviyo. */ id: string; attributes: { /** * Status of the asynchronous job. */ status: 'cancelled' | 'complete' | 'processing' | 'queued'; /** * The date and time the job was created in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ created_at: string; /** * The total number of operations to be processed by the job. See `completed_count` for the job's current progress. */ total_count: number; /** * The total number of operations that have been completed by the job. */ completed_count?: number | null; /** * The total number of operations that have failed as part of the job. */ failed_count?: number | null; /** * Date and time the job was completed in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ completed_at?: string | null; /** * Array of errors encountered during the processing of the job. */ errors?: Array<ApiJobErrorPayload> | null; /** * Date and time the job expires in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ expires_at?: string | null; }; links: ObjectLinks; }; type GetCouponCodeCreateJobResponseCollectionCompoundDocument = { data: Array<CouponCodeCreateJobResponseObjectResource & { relationships?: { 'coupon-codes'?: { data?: Array<{ type: CouponCodeEnum; /** * IDs of the created coupon codes. */ id: string; }>; links?: RelationshipLinks; }; }; }>; links?: CollectionLinks; }; type GetCouponCodeCreateJobResponseCompoundDocument = { data: CouponCodeCreateJobResponseObjectResource & { relationships?: { 'coupon-codes'?: { data?: Array<{ type: CouponCodeEnum; /** * IDs of the created coupon codes. */ id: string; }>; links?: RelationshipLinks; }; }; }; included?: Array<CouponCodeResponseObjectResource>; links?: ObjectLinks; }; type GetCatalogItemCategoriesRelationshipsResponseCollection = { data: Array<{ type: CatalogCategoryEnum; /** * The catalog category ID is a compound ID (string), with format: `{integration}:::{catalog}:::{external_id}`. Currently, the only supported integration type is `$custom`, and the only supported catalog is `$default`. */ id: string; }>; links?: CollectionLinks; }; type EventEnum = 'event'; type ProfileEnum = 'profile'; type MetricEnum = 'metric'; type AttributionEnum = 'attribution'; type FlowEnum = 'flow'; type MetricResponseObjectResource = { type: MetricEnum; /** * The Metric ID */ id: string; attributes: { /** * The name of the metric */ name?: string | null; /** * Creation time in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm) */ created?: string | null; /** * Last updated time in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm) */ updated?: string | null; /** * The integration associated with the event */ integration?: { [key: string]: unknown; } | null; }; links: ObjectLinks; }; type ProfileLocation = { /** * First line of street address */ address1?: string | null; /** * Second line of street address */ address2?: string | null; /** * City name */ city?: string | null; /** * Country name */ country?: string | null; /** * Latitude coordinate. We recommend providing a precision of four decimal places. */ latitude?: string | number | null; /** * Longitude coordinate. We recommend providing a precision of four decimal places. */ longitude?: string | number | null; /** * Region within a country, such as state or province */ region?: string | null; /** * Zip code */ zip?: string | null; /** * Time zone name. We recommend using time zones from the IANA Time Zone Database. */ timezone?: string | null; /** * IP Address */ ip?: string | null; }; type EmailMarketingSuppression = { /** * The reason the profile was suppressed. */ reason: 'HARD_BOUNCE' | 'INVALID_EMAIL' | 'SPAM_COMPLAINT' | 'UNSUBSCRIBE' | 'USER_SUPPRESSED'; /** * The timestamp when the profile was suppressed, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ timestamp: string; }; type EmailMarketingListSuppression = { /** * The ID of list to which the suppression applies. */ list_id: string; /** * The reason the profile was suppressed from the list. */ reason: string; /** * The timestamp when the profile was suppressed from the list, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ timestamp: string; }; type EmailMarketing = { /** * Whether or not this profile has implicit consent to receive email marketing. True if it does profile does not have any global suppressions. */ can_receive_email_marketing: boolean; /** * The consent status for email marketing. */ consent: string; /** * The timestamp when consent was recorded or updated for email marketing, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ consent_timestamp?: string | null; /** * The timestamp when a field on the email marketing object was last modified. */ last_updated?: string | null; /** * The method by which the profile was subscribed to email marketing. */ method?: string | null; /** * Additional details about the method by which the profile was subscribed to email marketing. This may be empty if no details were provided. */ method_detail?: string | null; /** * Additional detail provided by the caller when the profile was subscribed. This may be empty if no details were provided. */ custom_method_detail?: string | null; /** * Whether the profile was subscribed to email marketing using a double opt-in. */ double_optin?: boolean | null; /** * The global email marketing suppression for this profile. */ suppression?: Array<EmailMarketingSuppression> | null; /** * The list suppressions for this profile. */ list_suppressions?: Array<EmailMarketingListSuppression> | null; }; type EmailChannel = { marketing?: EmailMarketing; }; type SmsMarketing = { /** * Whether or not this profile is subscribed to receive SMS marketing. */ can_receive_sms_marketing: boolean; /** * The consent status for SMS marketing. */ consent: string; /** * The timestamp when consent was recorded or updated for SMS marketing, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ consent_timestamp?: string | null; /** * The method by which the profile was subscribed to SMS marketing. */ method?: string | null; /** * Additional details about the method which the profile was subscribed to SMS marketing. This may be empty if no details were provided. */ method_detail?: string | null; /** * The timestamp when the SMS consent record was last modified, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ last_updated?: string | null; }; type SmsTransactional = { /** * Whether or not this profile is subscribed to receive transactional SMS. */ can_receive_sms_transactional: boolean; /** * The consent status for SMS Transactional. */ consent: string; /** * The timestamp when consent was recorded or updated for Transactional SMS messaging , in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ consent_timestamp?: string | null; /** * The method by which the profile was subscribed to Transactional SMS messaging . */ method?: string | null; /** * Additional details about the method which the profile was subscribed to Transactional SMS messaging. This may be empty if no details were provided. */ method_detail?: string | null; /** * The timestamp when the SMS consent record was last modified, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ last_updated?: string | null; }; type SmsChannel = { marketing?: SmsMarketing; transactional?: SmsTransactional; }; type PushMarketing = { /** * Whether or not this profile is subscribed to receive mobile push. */ can_receive_push_marketing: boolean; /** * The consent status for mobile push marketing. */ consent: string; /** * The timestamp when the consent was last changed, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ consent_timestamp?: string | null; }; type PushChannel = { marketing?: PushMarketing; }; type WhatsappMarketingChannel = { /** * The consent status for the channel. */ consent: string; /** * The timestamp when consent was recorded or updated for the channel, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ consent_timestamp?: string | null; /** * The timestamp when the channel was last modified, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ last_updated?: string | null; /** * The timestamp when the channel was created, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ created_timestamp?: string | null; /** * Channel-specific metadata containing additional information about the permission. */ metadata?: { [key: string]: unknown; } | null; /** * Whether the profile can receive messages on this channel. */ can_receive: boolean; /** * Optional expiration date for the permission, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ valid_until?: string | null; /** * Phone number to which the consent was granted for. */ phone_number: string; }; type WhatsappTransactionalChannel = { /** * The consent status for the channel. */ consent: string; /** * The timestamp when consent was recorded or updated for the channel, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ consent_timestamp?: string | null; /** * The timestamp when the channel was last modified, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ last_updated?: string | null; /** * The timestamp when the channel was created, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ created_timestamp?: string | null; /** * Channel-specific metadata containing additional information about the permission. */ metadata?: { [key: string]: unknown; } | null; /** * Whether the profile can receive messages on this channel. */ can_receive: boolean; /** * Optional expiration date for the permission, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ valid_until?: string | null; /** * Phone number to which the consent was granted for. */ phone_number: string; }; type WhatsappConversationalChannel = { /** * The consent status for the channel. */ consent: string; /** * The timestamp when consent was recorded or updated for the channel, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ consent_timestamp?: string | null; /** * The timestamp when the channel was last modified, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ last_updated?: string | null; /** * The timestamp when the channel was created, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ created_timestamp?: string | null; /** * Channel-specific metadata containing additional information about the permission. */ metadata?: { [key: string]: unknown; } | null; /** * Whether the profile can receive messages on this channel. */ can_receive: boolean; /** * Optional expiration date for the permission, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm). */ valid_until?: string | null; /** * Phone number to which the consent was granted for. */ phone_number: string; }; type WhatsappChannel = { marketing?: WhatsappMarketingChannel; transactional?: WhatsappTransactionalChannel; conversational?: WhatsappConversationalChannel; }; type Subscriptions = { email?: EmailChannel; sms?: SmsChannel; mobile_push?: PushChannel; whatsapp?: WhatsappChannel; }; type PredictiveAnalytics = { /** * Total value of all historically placed orders */ historic_clv?: number | null; /** * Predicted value of all placed orders in the next 365 days */ predicted_clv?: number | null; /** * Sum of historic and predicted CLV */ total_clv?: number | null; /** * Number of already placed orders */ historic_number_of_orders?: number | null; /** * Predicted number of placed orders in the next 365 days */ predicted_number_of_orders?: number | null; /** * Average number of days between orders (None if only one order has been placed) */ average_days_between_orders?: number | null; /** * Average value of placed orders */ average_order_value?: number | null; /** * Probability the customer has churned */ churn_probability?: number | null; /** * Expected date of next order, as calculated at the time of their most recent order */ expected_date_of_next_order?: string | null; /** * List of channels ranked by their predicted effectiveness for this profile, with the best channel being listed first at index 0 */ ranked_channel_affinity?: Array<'email' | 'push' | 'sms'> | null; }; type ListEnum = 'list'; type SegmentEnum = 'segment'; type PushTokenEnum = 'push-token'; type ProfileResponseObjectResource = { type: ProfileEnum; /** * Primary key that uniquely identifies this profile. Generated by Klaviyo. */ id?: string | null; attributes: { /** * Individual's email address */ email?: string | null; /** * Individual's phone number in E.164 format */ phone_number?: string | null; /** * A unique identifier used by customers to associate Klaviyo profiles with profiles in an external system, such as a point-of-sale system. Format varies based on the external system. */ external_id?: string | null; /** * Individual's first name */ first_name?: string | null; /** * Individual's last name */ last_name?: string | null; /** * Name of the company or organization within the company for whom the individual works */ organization?: string | null; /** * The locale of the profile, in the IETF BCP 47 language tag format like (ISO 639-1/2)-(ISO 3166 alpha-2) */ locale?: string | null; /** * Individual's job title */ title?: string | null; /** * URL pointing to the location of a profile image */ image?: string | null; /** * Date and time when the profile was created, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm) */ created?: string | null; /** * Date and time when the profile was last updated, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm) */ updated?: string | null; /** * Date and time of the most recent event the triggered an update to the profile, in ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm) */ last_event_date?: string | null; location?: ProfileLocation; /** * An object containing key/value pairs for any custom properties assigned to this profile */ properties?: { [key: string]: unknown; } | null; }; links: ObjectLinks; }; type CampaignEnum = 'campaign'; type CampaignMessageEnum = 'campaign-message'; type FlowMessageEnum = 'flow-message'; type AttributionResponseObjectResource = { type: AttributionEnum; /** * The ID of the attribution */ id: string; relationships?: { event?: { data?: { type: EventEnum; /** * Event */ id: string; }; }; 'attributed-event'?: { data?: { type: EventEnum; /** * Attributed Event */ id: string; }; }; campaign?: { data?: { type: CampaignEnum; /** * Attributed Campaign */ id: string; }; }; 'campaign-message'?: { data?: { type: CampaignMessageEnum; /** * Attributed Campaign Message */ id: string; }; }; flow?: { data?: { type: FlowEnum; /** * Attributed Flow */ id: string; }; }; 'flow-message'?: { data?: { type: FlowMessageEnum; /** * Attributed Flow Message */ id: string; }; }; 'flow-message-variation'?: { data?: { type: FlowMessageEnum; /** * Attributed Flow Message Variation */ id: string; }; }; }; links: ObjectLinks; }; type EventResponseObjectResource = { type: EventEnum; /** * The Event ID */ id: string; attributes: { /** * Event timestamp in seconds */ timestamp?: number | null; /** * Event properties, can include identifiers and extra properties */ event_properties?: { [key: string]: unknown; } | null; /** * Event timestamp in ISO8601 format (YYYY-MM-DDTHH:MM:SS+hh:mm) */ datetime?: string | null; /** * A unique identifier for the event, this can be used as a cursor in pagination */ uuid?: string | null; }; links: ObjectLinks; }; type GetEventResponseCollectionCompoundDocument = { data: Array<EventResponseObjectResource & { relationships?: { profile?: { data?: { type: ProfileEnum; /** * Profile ID of the associated profile, if available */ id: string; }; links?: RelationshipLinks; }; metric?: { data?: { type: MetricEnum; /** * The Metric ID */ id: string; }; links?: RelationshipLinks; }; attributions?: { data?: Array<{ type: AttributionEnum; /** * Attributions for this event */ id: string; }>; links?: RelationshipLinks; }; }; }>; links?: CollectionLinks; included?: Array<MetricResponseObjectResource | ProfileResponseObjectResource | AttributionResponseObjectResource>; }; type GetEventResponseCompoundDocument = { data: EventResponseObjectResource & { relationships?: { profile?: { data?: { type: ProfileEnum; /** * Profile ID of the associated profile, if available */ id: string; }; links?: RelationshipLinks; }; metric?: { data?: { type: MetricEnum; /** * The Metric ID */ id: string; }; links?: RelationshipLinks; }; attributions?: { data?: Array<{ type: AttributionEnum; /** * Attributions for this event */ id: string; }>; links?: RelationshipLinks; }; }; }; included?: Array<MetricResponseObjectResource | ProfileResponseObjectResource | AttributionResponseObjectResource>; links?: ObjectLinks; }; type GetMetricResponse = { data: MetricResponseObjectResource & { relationships?: { 'flow-triggers'?: { links?: RelationshipLinks; }; }; }; links?: ObjectLinks; }; type GetEventMetricRelationshipResponse = { data: { type: MetricEnum; /** * The Metric ID */ id: string; }; links?: ObjectLinks; }; type GetProfileResponse = { data: ProfileResponseObjectResource & { relationships?: { lists?: { links?: RelationshipLinks; }; segments?: { links?: RelationshipLinks; }; 'push-tokens'?: { links?: RelationshipLinks; }; }; } & { type?: ProfileEnum; attributes?: { subscriptions?: Subscriptions; predictive_analytics?: PredictiveAnalytics; }; }; links?: ObjectLinks; }; type GetEventProfileRelationshipResponse = { data: { type: ProfileEnum; /** * Primary key that uniquely identifies this profile. Generated by Klaviyo. */ id: string; }; links?: ObjectLinks; }; type FlowActionEnum = 'flow-action'; type TagEnum = 'tag'; type FlowResponseObjectResource = { type: FlowEnum; id: string; attributes: { name?: string | null; status?: string | null; archived?: boolean | null; created?: string | null; updated?: string | null; /** * Corresponds to the object which triggered the flow. */ trigger_type?: 'Added to List' | 'Date Based' | 'Low Inventory' | 'Metric' | 'Price Drop' | 'Unconfigured'; }; links: ObjectLinks; }; type GetMetricResponseCollectionCompoundDocument = { data: Array<MetricResponseObjectResource & { relationships?: { 'flow-triggers'?: { data?: Array<{ type: FlowEnum; id: string; }>; links?: RelationshipLinks; }; }; }>; links?: CollectionLinks; included?: Array<FlowResponseObjectResource>; }; type GetMetricResponseCompoundDocument = { data: MetricResponseObjectResource & { relationships?: { 'flow-triggers'?: { data?: Array<{ type: FlowEnum; id: string; }>; links?: RelationshipLinks; }; }; }; included?: Array<FlowResponseObjectR