Skip to content

Commit d2cce1d

Browse files
authored
Klaviyo - update to api v2025-04-15 (#16581)
* update to api v2025-04-15 * pnpm-lock.yaml
1 parent b36acd5 commit d2cce1d

File tree

6 files changed

+116
-47
lines changed

6 files changed

+116
-47
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import klaviyo from "../../klaviyo.app.mjs";
44
export default {
55
key: "klaviyo-add-member-to-list",
66
name: "Add Member To List",
7-
description: "Add member to a specific list. [See the docs here](https://developers.klaviyo.com/en/v1-2/reference/add-members)",
8-
version: "1.0.0",
7+
description: "Add member to a specific list. [See the documentation](https://developers.klaviyo.com/en/reference/add_profiles_to_list)",
8+
version: "1.0.1",
99
type: "action",
1010
props: {
1111
klaviyo,
@@ -31,7 +31,7 @@ export default {
3131
})),
3232
});
3333

34-
$.export("$summary", `${this.profileId} successfully added to "${this.list.label}"!`);
34+
$.export("$summary", `Member(s) successfully added to "${this.list.label}"!`);
3535
return response.data;
3636
},
3737
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import klaviyo from "../../klaviyo.app.mjs";
33
export default {
44
key: "klaviyo-create-new-list",
55
name: "Create New List",
6-
description: "Creates a new list in an account. [See the docs here](https://developers.klaviyo.com/en/v1-2/reference/create-list)",
7-
version: "0.0.2",
6+
description: "Creates a new list in an account. [See the documentation](https://developers.klaviyo.com/en/reference/create_list)",
7+
version: "0.0.3",
88
type: "action",
99
props: {
1010
klaviyo,

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

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,62 @@ import klaviyo from "../../klaviyo.app.mjs";
33
export default {
44
key: "klaviyo-get-lists",
55
name: "Get Lists",
6-
description: "Get a listing of all of the lists in an account. [See the docs here](https://developers.klaviyo.com/en/v1-2/reference/get-lists)",
7-
version: "0.0.3",
6+
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.4",
88
type: "action",
99
props: {
1010
klaviyo,
11+
sort: {
12+
type: "string",
13+
label: "Sort",
14+
description: "The field to sort by",
15+
options: [
16+
"created",
17+
"id",
18+
"name",
19+
"updated",
20+
],
21+
default: "created",
22+
optional: true,
23+
},
24+
sortDirection: {
25+
type: "string",
26+
label: "Sort Direction",
27+
description: "Whether to sort ascending or descending. Default: `descending`",
28+
options: [
29+
"asc",
30+
"desc",
31+
],
32+
default: "desc",
33+
optional: true,
34+
},
35+
maxResults: {
36+
type: "integer",
37+
label: "Max Results",
38+
description: "The maximum number of results to return",
39+
default: 100,
40+
optional: true,
41+
},
1142
},
1243
async run({ $ }) {
13-
const response = await this.klaviyo.getLists();
44+
const lists = this.klaviyo.paginate({
45+
fn: this.klaviyo.getLists,
46+
opts: {
47+
sort: `${this.sortDirection === "desc"
48+
? "-"
49+
: ""}${this.sort}`,
50+
},
51+
max: this.maxResults,
52+
});
1453

15-
$.export("$summary", "List Successfully fetched!");
16-
return response.body;
54+
const results = [];
55+
for await (const list of lists) {
56+
results.push(list);
57+
}
58+
59+
$.export("$summary", `Successfully fetched ${results.length} list${results.length === 1
60+
? ""
61+
: "s"}`);
62+
return results;
1763
},
1864
};

components/klaviyo/klaviyo.app.mjs

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,42 @@ export default {
1010
list: {
1111
type: "string",
1212
label: "List",
13-
description: "The list which will be affected.",
13+
description: "The list which will be affected",
1414
withLabel: true,
15-
async options() {
16-
const { body: { data } } = await this.getLists();
15+
async options({ prevContext }) {
16+
const {
17+
body: {
18+
data, links,
19+
},
20+
} = await this.getLists({
21+
pageCursor: prevContext?.nextCursor,
22+
});
1723

18-
return data.map(({
19-
id: value, attributes: { name: label },
20-
}) => ({
21-
label,
22-
value,
23-
}));
24+
return {
25+
options: data.map(({
26+
id: value, attributes: { name: label },
27+
}) => ({
28+
label,
29+
value,
30+
})),
31+
context: {
32+
nextCursor: this.getCursorFromNextLink(links?.next),
33+
},
34+
};
2435
},
2536
},
2637
profileIds: {
2738
type: "string[]",
28-
label: "Profile Ids",
29-
description: "An array with profile Ids.",
39+
label: "Profile IDs",
40+
description: "An array of profile IDs",
3041
withLabel: true,
3142
async options({ prevContext }) {
3243
const {
3344
body: {
3445
data, links,
3546
},
3647
} = await this.listProfiles({
37-
"page[cursor]": prevContext.nextCursor,
48+
pageCursor: prevContext?.nextCursor,
3849
});
3950

4051
return {
@@ -45,15 +56,15 @@ export default {
4556
value,
4657
})),
4758
context: {
48-
nextCursor: links.next,
59+
nextCursor: this.getCursorFromNextLink(links?.next),
4960
},
5061
};
5162
},
5263
},
5364
listName: {
5465
type: "string",
5566
label: "List Name",
56-
description: "The name of the new list.",
67+
description: "The name of the new list",
5768
},
5869
},
5970
methods: {
@@ -64,9 +75,9 @@ export default {
6475
this.sdk();
6576
return Lists.createList(data);
6677
},
67-
getLists() {
78+
getLists(opts = {}) {
6879
this.sdk();
69-
return Lists.getLists();
80+
return Lists.getLists(opts);
7081
},
7182
subscribeProfiles({
7283
listId, ...opts
@@ -78,5 +89,31 @@ export default {
7889
this.sdk();
7990
return Profiles.getProfiles(opts);
8091
},
92+
getCursorFromNextLink(url) {
93+
if (!url) {
94+
return;
95+
}
96+
return (new URL(url)).searchParams.get("page[cursor]");
97+
},
98+
async *paginate({
99+
fn, opts = {}, max,
100+
}) {
101+
let hasMore, count = 0;
102+
do {
103+
const {
104+
body: {
105+
data, links,
106+
},
107+
} = await fn(opts);
108+
for (const item of data) {
109+
yield item;
110+
if (max && ++count >= max) {
111+
return;
112+
}
113+
}
114+
opts.pageCursor = this.getCursorFromNextLink(links?.next);
115+
hasMore = links?.next;
116+
} while (hasMore);
117+
},
81118
},
82119
};

components/klaviyo/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/klaviyo",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "Pipedream Klaviyo Components",
55
"main": "klaviyo.app.mjs",
66
"keywords": [
@@ -14,6 +14,6 @@
1414
},
1515
"dependencies": {
1616
"@babel/core": "^7.0.0-0",
17-
"klaviyo-api": "^11.0.0"
17+
"klaviyo-api": "^18.0.0"
1818
}
1919
}

pnpm-lock.yaml

Lines changed: 5 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)