Skip to content

Commit

Permalink
[MAIN] [STRATCONN] 4119 klaviyo fixed blank audience creation. (#2419)
Browse files Browse the repository at this point in the history
* list_id fields added in klaviyo

* decriptions changed

* Unit test cases added
  • Loading branch information
AnkitSegment authored Sep 24, 2024
1 parent 891332d commit 35f8e69
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ const createAudienceInput = {
settings: {
api_key: ''
},
audienceName: ''
audienceName: '',
audienceSettings: {
listId: ''
}
}

const getAudienceInput = {
Expand Down Expand Up @@ -97,6 +100,12 @@ describe('Klaviyo (actions)', () => {
externalId: 'XYZABC'
})
})

it('Should return list_id if list_id is set in audienceSetting', async () => {
createAudienceInput.audienceSettings.listId = 'XYZABC'
const r = await testDestination.createAudience(createAudienceInput)
expect(r).toEqual({ externalId: 'XYZABC' })
})
})

describe('getAudience', () => {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 16 additions & 3 deletions packages/destination-actions/src/destinations/klaviyo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
PayloadValidationError,
APIError
} from '@segment/actions-core'
import type { Settings } from './generated-types'
import type { Settings, AudienceSettings } from './generated-types'

import { API_URL } from './config'
import upsertProfile from './upsertProfile'
Expand All @@ -18,7 +18,7 @@ import removeProfile from './removeProfile'

import unsubscribeProfile from './unsubscribeProfile'

const destination: AudienceDestinationDefinition<Settings> = {
const destination: AudienceDestinationDefinition<Settings, AudienceSettings> = {
name: 'Klaviyo (Actions)',
slug: 'actions-klaviyo',
mode: 'cloud',
Expand Down Expand Up @@ -64,7 +64,14 @@ const destination: AudienceDestinationDefinition<Settings> = {
headers: buildHeaders(settings.api_key)
}
},
audienceFields: {},
audienceFields: {
listId: {
label: 'List Id',
description: `Insert the ID of the default list that you'd like to subscribe users to when you call .identify().
NOTE: List ID takes precedence set within Actions.`,
type: 'string'
}
},
audienceConfig: {
mode: {
type: 'synced',
Expand All @@ -73,6 +80,12 @@ const destination: AudienceDestinationDefinition<Settings> = {
async createAudience(request, createAudienceInput) {
const audienceName = createAudienceInput.audienceName
const apiKey = createAudienceInput.settings.api_key
const defaultAudienceId = createAudienceInput.audienceSettings?.listId

if (defaultAudienceId) {
return { externalId: defaultAudienceId }
}

if (!audienceName) {
throw new PayloadValidationError('Missing audience name value')
}
Expand Down

0 comments on commit 35f8e69

Please sign in to comment.