Skip to content

Commit 9c4b1e1

Browse files
committed
[APP] Klaviyo - Oauth Version with updated functionality
1 parent e91b480 commit 9c4b1e1

File tree

14 files changed

+563
-22
lines changed

14 files changed

+563
-22
lines changed

components/klaviyo/actions/add-member-to-list/add-member-to-list.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "klaviyo-add-member-to-list",
66
name: "Add Member To List",
77
description: "Add member to a specific list. [See the documentation](https://developers.klaviyo.com/en/reference/add_profiles_to_list)",
8-
version: "1.0.3",
8+
version: "1.0.4",
99
annotations: {
1010
destructiveHint: false,
1111
openWorldHint: true,
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
import klaviyo from "../../klaviyo.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "klaviyo-create-event",
6+
name: "Create Event",
7+
description: "Create a new event to track a profile's activity. [See the documentation](https://developers.klaviyo.com/en/reference/create_event)",
8+
version: "0.0.1",
9+
type: "action",
10+
annotations: {
11+
destructiveHint: false,
12+
openWorldHint: true,
13+
readOnlyHint: false,
14+
},
15+
props: {
16+
klaviyo,
17+
// eslint-disable-next-line pipedream/props-label, pipedream/props-description
18+
info: {
19+
type: "alert",
20+
alertType: "warning",
21+
content: "At least one profile identifier (**Email**, **Phone Number**, **External ID**, or **Profile ID**) must be provided",
22+
},
23+
metricName: {
24+
type: "string",
25+
label: "Event Name",
26+
description: "The name of the event/metric to track (e.g., `Viewed Product`, `Added to Cart`)",
27+
},
28+
properties: {
29+
type: "object",
30+
label: "Event Properties",
31+
description: `Custom properties for the event as a JSON object with key-value pairs.
32+
33+
**Example:**
34+
\`\`\`json
35+
{
36+
"Brand": "Kids Book",
37+
"ProductID": 1111,
38+
"ProductName": "Winnie the Pooh"
39+
}
40+
\`\`\``,
41+
},
42+
email: {
43+
type: "string",
44+
label: "Email",
45+
description: "The email address of the profile",
46+
optional: true,
47+
},
48+
phoneNumber: {
49+
type: "string",
50+
label: "Phone Number",
51+
description: "The phone number of the profile (E.164 format, e.g., `+12345678901`)",
52+
optional: true,
53+
},
54+
externalId: {
55+
type: "string",
56+
label: "External ID",
57+
description: "A unique identifier from an external system",
58+
optional: true,
59+
},
60+
profileId: {
61+
type: "string",
62+
label: "Profile ID",
63+
description: "The Klaviyo profile ID",
64+
optional: true,
65+
propDefinition: [
66+
klaviyo,
67+
"profileIds",
68+
],
69+
},
70+
value: {
71+
type: "string",
72+
label: "Event Value",
73+
description: "A numeric value to associate with this event (e.g., `100.00`)",
74+
optional: true,
75+
},
76+
uniqueId: {
77+
type: "string",
78+
label: "Unique ID",
79+
description: "A unique identifier for the event. Use uuidv4 or similar. If not provided, Klaviyo will generate one.",
80+
optional: true,
81+
},
82+
time: {
83+
type: "string",
84+
label: "Event Time",
85+
description: "When the event occurred in ISO 8601 format (e.g., `2023-09-15T12:00:00Z`). Defaults to current time if not provided.",
86+
optional: true,
87+
},
88+
profileProperties: {
89+
type: "object",
90+
label: "Profile Properties",
91+
description: "Optional properties to update on the profile as a JSON object",
92+
optional: true,
93+
},
94+
},
95+
async run({ $ }) {
96+
const {
97+
klaviyo,
98+
metricName,
99+
email,
100+
phoneNumber,
101+
externalId,
102+
profileId,
103+
properties,
104+
value,
105+
uniqueId,
106+
time,
107+
profileProperties,
108+
} = this;
109+
110+
if (!email && !phoneNumber && !externalId && !profileId) {
111+
throw new Error("At least one profile identifier (email, phone number, external ID, or profile ID) must be provided");
112+
}
113+
114+
const profileData = {
115+
type: "profile",
116+
};
117+
118+
if (profileId) {
119+
profileData.id = profileId;
120+
}
121+
122+
const profileAttributes = {};
123+
124+
if (email) {
125+
profileAttributes.email = email;
126+
}
127+
128+
if (phoneNumber) {
129+
profileAttributes.phoneNumber = phoneNumber;
130+
}
131+
132+
if (externalId) {
133+
profileAttributes.externalId = externalId;
134+
}
135+
136+
if (profileProperties) {
137+
profileAttributes.properties = parseObject(profileProperties);
138+
}
139+
140+
if (Object.keys(profileAttributes).length > 0) {
141+
profileData.attributes = profileAttributes;
142+
}
143+
144+
const eventAttributes = {
145+
metric: {
146+
data: {
147+
type: "metric",
148+
attributes: {
149+
name: metricName,
150+
},
151+
},
152+
},
153+
profile: {
154+
data: profileData,
155+
},
156+
};
157+
158+
if (properties) {
159+
eventAttributes.properties = parseObject(properties);
160+
}
161+
162+
if (value) {
163+
eventAttributes.value = value;
164+
}
165+
166+
if (uniqueId) {
167+
eventAttributes.uniqueId = uniqueId;
168+
}
169+
170+
if (time) {
171+
eventAttributes.time = time;
172+
}
173+
174+
const data = {
175+
type: "event",
176+
attributes: eventAttributes,
177+
};
178+
179+
try {
180+
await klaviyo.createEvent({
181+
data,
182+
});
183+
184+
$.export("$summary", `Successfully created event "${metricName}" for profile`);
185+
return {
186+
success: true,
187+
};
188+
189+
} catch (error) {
190+
throw new Error(JSON.stringify(error.response.data));
191+
}
192+
},
193+
};

components/klaviyo/actions/create-new-list/create-new-list.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "klaviyo-create-new-list",
55
name: "Create New List",
66
description: "Creates a new list in an account. [See the documentation](https://developers.klaviyo.com/en/reference/create_list)",
7-
version: "0.0.5",
7+
version: "0.0.6",
88
annotations: {
99
destructiveHint: false,
1010
openWorldHint: true,
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
import { parseObject } from "../../common/utils.mjs";
2+
import klaviyo from "../../klaviyo.app.mjs";
3+
4+
export default {
5+
key: "klaviyo-create-update-profile",
6+
name: "Create Or Update Profile",
7+
description: "Create or update a profile's custom properties. [See the documentation](https://developers.klaviyo.com/en/reference/create_or_update_profile)",
8+
version: "0.0.1",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: false,
13+
},
14+
type: "action",
15+
props: {
16+
klaviyo,
17+
// eslint-disable-next-line pipedream/props-label, pipedream/props-description
18+
info: {
19+
type: "alert",
20+
alertType: "warning",
21+
content: "At least one identifier (**Email**, **Phone Number**, or **External ID**) must be provided",
22+
},
23+
email: {
24+
type: "string",
25+
label: "Email",
26+
description: "The email address of the profile",
27+
optional: true,
28+
},
29+
phoneNumber: {
30+
type: "string",
31+
label: "Phone Number",
32+
description: "The phone number of the profile (E.164 format, e.g., `+12345678901`)",
33+
optional: true,
34+
},
35+
externalId: {
36+
type: "string",
37+
label: "External ID",
38+
description: "A unique identifier from an external system",
39+
optional: true,
40+
},
41+
firstName: {
42+
type: "string",
43+
label: "First Name",
44+
description: "The first name of the profile",
45+
optional: true,
46+
},
47+
lastName: {
48+
type: "string",
49+
label: "Last Name",
50+
description: "The last name of the profile",
51+
optional: true,
52+
},
53+
organization: {
54+
type: "string",
55+
label: "Organization",
56+
description: "The organization of the profile",
57+
optional: true,
58+
},
59+
title: {
60+
type: "string",
61+
label: "Title",
62+
description: "The title of the profile",
63+
optional: true,
64+
},
65+
image: {
66+
type: "string",
67+
label: "Image URL",
68+
description: "URL of the profile's image",
69+
optional: true,
70+
},
71+
location: {
72+
type: "object",
73+
label: "Location",
74+
description: `Location information as a JSON object with properties like \`address1\`, \`address2\`, \`city\`, \`country\`, \`region\`, \`zip\`, \`timezone\`, \`latitude\`, \`longitude\`
75+
76+
**Example:**
77+
\`\`\`json
78+
{
79+
"address1": "123 Main St",
80+
"address2": "Apt 4B",
81+
"city": "New York",
82+
"country": "USA",
83+
"region": "NY",
84+
}
85+
\`\`\``,
86+
optional: true,
87+
},
88+
properties: {
89+
type: "object",
90+
label: "Custom Properties",
91+
description: "Custom properties as a JSON object with key-value pairs",
92+
optional: true,
93+
},
94+
},
95+
async run({ $ }) {
96+
const {
97+
klaviyo,
98+
email,
99+
phoneNumber,
100+
externalId,
101+
firstName,
102+
lastName,
103+
organization,
104+
title,
105+
image,
106+
location,
107+
properties,
108+
} = this;
109+
110+
if (!email && !phoneNumber && !externalId) {
111+
throw new Error("At least one identifier (email, phone number, or external ID) must be provided");
112+
}
113+
114+
const attributes = {};
115+
116+
if (email) {
117+
attributes.email = email;
118+
}
119+
120+
if (phoneNumber) {
121+
attributes.phoneNumber = phoneNumber;
122+
}
123+
124+
if (externalId) {
125+
attributes.externalId = externalId;
126+
}
127+
128+
if (firstName) {
129+
attributes.firstName = firstName;
130+
}
131+
132+
if (lastName) {
133+
attributes.lastName = lastName;
134+
}
135+
136+
if (organization) {
137+
attributes.organization = organization;
138+
}
139+
140+
if (title) {
141+
attributes.title = title;
142+
}
143+
144+
if (image) {
145+
attributes.image = image;
146+
}
147+
148+
if (location) {
149+
attributes.location = parseObject(location);
150+
}
151+
152+
if (properties) {
153+
attributes.properties = parseObject(properties);
154+
}
155+
156+
const data = {
157+
type: "profile",
158+
attributes,
159+
};
160+
161+
try {
162+
const { response } = await klaviyo.createOrUpdateProfile({
163+
data,
164+
});
165+
166+
$.export("$summary", "Successfully updated profile properties");
167+
return response.data.data;
168+
} catch (error) {
169+
throw new Error(JSON.stringify(error.response.data));
170+
}
171+
},
172+
};

components/klaviyo/actions/get-lists/get-lists.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "klaviyo-get-lists",
55
name: "Get Lists",
66
description: "Get a listing of all of the lists in an account. [See the documentation](https://developers.klaviyo.com/en/reference/get_lists)",
7-
version: "0.0.6",
7+
version: "0.0.7",
88
annotations: {
99
destructiveHint: false,
1010
openWorldHint: true,

0 commit comments

Comments
 (0)