From e9f23701a9bd6382cc45168981e113ad36d3fe8f Mon Sep 17 00:00:00 2001 From: Harsh Joshi Date: Fri, 24 Nov 2023 11:42:37 +0530 Subject: [PATCH] Add enable batching --- .../src/destinations/klaviyo/functions.ts | 2 +- .../klaviyo/upsertProfile/generated-types.ts | 4 ++++ .../src/destinations/klaviyo/upsertProfile/index.ts | 9 ++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/destination-actions/src/destinations/klaviyo/functions.ts b/packages/destination-actions/src/destinations/klaviyo/functions.ts index fee1bca1b5..81b0210488 100644 --- a/packages/destination-actions/src/destinations/klaviyo/functions.ts +++ b/packages/destination-actions/src/destinations/klaviyo/functions.ts @@ -55,7 +55,7 @@ export const createImportJobPayload = (profiles: Payload[], listId?: string): { type: 'profile-bulk-import-job', attributes: { profiles: { - data: profiles.map(({ list_id, ...attributes }) => ({ + data: profiles.map(({ list_id, enable_batching, ...attributes }) => ({ type: 'profile', attributes })) diff --git a/packages/destination-actions/src/destinations/klaviyo/upsertProfile/generated-types.ts b/packages/destination-actions/src/destinations/klaviyo/upsertProfile/generated-types.ts index 8c359e5c39..5941e33584 100644 --- a/packages/destination-actions/src/destinations/klaviyo/upsertProfile/generated-types.ts +++ b/packages/destination-actions/src/destinations/klaviyo/upsertProfile/generated-types.ts @@ -5,6 +5,10 @@ export interface Payload { * Individual's email address. One of External ID, Phone Number and Email required. */ email?: string + /** + * When enabled, the action will use the klaviyo batch API. + */ + enable_batching?: boolean /** * Individual's phone number in E.164 format. If SMS is not enabled and if you use Phone Number as identifier, then you have to provide one of Email or External ID. */ diff --git a/packages/destination-actions/src/destinations/klaviyo/upsertProfile/index.ts b/packages/destination-actions/src/destinations/klaviyo/upsertProfile/index.ts index a47e757f35..bfd42b6078 100644 --- a/packages/destination-actions/src/destinations/klaviyo/upsertProfile/index.ts +++ b/packages/destination-actions/src/destinations/klaviyo/upsertProfile/index.ts @@ -19,6 +19,11 @@ const action: ActionDefinition = { format: 'email', default: { '@path': '$.traits.email' } }, + enable_batching: { + type: 'boolean', + label: 'Batch Data to Klaviyo', + description: 'When enabled, the action will use the klaviyo batch API.' + }, phone_number: { label: 'Phone Number', description: `Individual's phone number in E.164 format. If SMS is not enabled and if you use Phone Number as identifier, then you have to provide one of Email or External ID.`, @@ -135,7 +140,7 @@ const action: ActionDefinition = { } }, perform: async (request, { payload }) => { - const { email, external_id, phone_number, list_id, ...otherAttributes } = payload + const { email, external_id, phone_number, list_id, enable_batching, ...otherAttributes } = payload if (!email && !phone_number && !external_id) { throw new PayloadValidationError('One of External ID, Phone Number and Email is required.') @@ -192,10 +197,8 @@ const action: ActionDefinition = { performBatch: async (request, { payload }) => { payload = payload.filter((profile) => profile.email || profile.external_id || profile.phone_number) - console.log(payload) const profilesWithList = payload.filter((profile) => profile.list_id) const profilesWithoutList = payload.filter((profile) => !profile.list_id) - console.log(profilesWithList, profilesWithoutList) let importResponseWithList let importResponseWithoutList