-
Notifications
You must be signed in to change notification settings - Fork 306
Expand file tree
/
Copy pathindex.ts
More file actions
50 lines (48 loc) · 1.93 KB
/
index.ts
File metadata and controls
50 lines (48 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import type { ActionDefinition } from '@segment/actions-core'
import type { Settings } from '../generated-types'
import type { Payload } from './generated-types'
import { TALON_ONE_API_VERSION } from '../versioning-info'
import { attribute, addAudienceId, deleteAudienceId, customerProfileId } from '../t1-properties'
const action: ActionDefinition<Settings, Payload> = {
title: 'Update customer profile',
description:
'This updates attributes and audiences for a single customer profile. Create all the required attributes and audiences before using this Action.',
fields: {
customerProfileId: { ...customerProfileId },
skipNonExistingAttributes: {
type: 'boolean',
label: 'Skip Non-existing Attributes Flag',
description:
'Indicates whether to skip non-existing attributes. If `Yes`, the non-existing attributes are skipped and a 400 error is not returned. If `No`, a 400 error is returned in case of non-existing attributes.',
default: false,
required: false
},
deleteAudienceIds: { ...deleteAudienceId },
addAudienceIds: { ...addAudienceId },
runRuleEngine: {
label: 'Run rule engine',
description: 'This runs rule engine in Talon.One upon updating customer profile. Set to true to trigger rules.',
type: 'boolean',
default: true
},
attributes: { ...attribute }
},
perform: (request, { payload }) => {
let requestUrl = `https://integration.talon.one/segment/${TALON_ONE_API_VERSION}/customer_profiles/${payload.customerProfileId}`
if (payload.skipNonExistingAttributes) {
requestUrl += '?skipNonExistingAttributes=true'
}
return request(requestUrl, {
method: 'put',
json: {
audiencesChanges: {
adds: payload.addAudienceIds,
deletes: payload.deleteAudienceIds
},
runRuleEngine: payload.runRuleEngine,
attributes: payload.attributes
}
})
}
}
export default action