1 | |
2 |
|
3 | |
4 | * List Marketing Emails |
5 | * List marketing emails, optionally filtered by creation/update date (ISO 8601) and with send statistics. Requires the content scope. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Hubspot, |
9 | limit: number | undefined, |
10 | after: string | undefined, |
11 | created_after: string | undefined, |
12 | created_before: string | undefined, |
13 | updated_after: string | undefined, |
14 | updated_before: string | undefined, |
15 | include_stats: boolean | undefined, |
16 | archived: boolean | undefined, |
17 | sort: string | undefined |
18 | ) { |
19 | const url = new URL(`https://api.hubapi.com/marketing/v3/emails`) |
20 | if (limit != null) url.searchParams.append("limit", String(limit)) |
21 | if (after != null && after !== "") url.searchParams.append("after", after) |
22 | if (created_after != null && created_after !== "") |
23 | url.searchParams.append("createdAfter", created_after) |
24 | if (created_before != null && created_before !== "") |
25 | url.searchParams.append("createdBefore", created_before) |
26 | if (updated_after != null && updated_after !== "") |
27 | url.searchParams.append("updatedAfter", updated_after) |
28 | if (updated_before != null && updated_before !== "") |
29 | url.searchParams.append("updatedBefore", updated_before) |
30 | if (include_stats) |
31 | url.searchParams.append("includeStats", String(include_stats)) |
32 | if (archived) url.searchParams.append("archived", String(archived)) |
33 | if (sort != null && sort !== "") url.searchParams.append("sort", sort) |
34 |
|
35 | const response = await fetch(url, { |
36 | headers: { |
37 | Authorization: `Bearer ${auth.token}`, |
38 | Accept: "application/json", |
39 | }, |
40 | }) |
41 |
|
42 | if (!response.ok) { |
43 | throw new Error(`${response.status} ${await response.text()}`) |
44 | } |
45 |
|
46 | return await response.json() |
47 | } |
48 |
|