1 | |
2 |
|
3 | |
4 | * List Campaigns |
5 | * List marketing campaigns. Requires the marketing.campaigns.read scope (Marketing Hub Professional or Enterprise). |
6 | */ |
7 | export async function main( |
8 | auth: RT.Hubspot, |
9 | limit: number | undefined, |
10 | after: string | undefined, |
11 | name: string | undefined, |
12 | sort: string | undefined, |
13 | properties: string[] | undefined |
14 | ) { |
15 | const url = new URL(`https://api.hubapi.com/marketing/v3/campaigns`) |
16 | if (limit != null) url.searchParams.append("limit", String(limit)) |
17 | if (after != null && after !== "") url.searchParams.append("after", after) |
18 | if (name != null && name !== "") url.searchParams.append("name", name) |
19 | if (sort != null && sort !== "") url.searchParams.append("sort", sort) |
20 | if (properties?.length) |
21 | url.searchParams.append("properties", properties.join(",")) |
22 |
|
23 | const response = await fetch(url, { |
24 | headers: { |
25 | Authorization: `Bearer ${auth.token}`, |
26 | Accept: "application/json", |
27 | }, |
28 | }) |
29 |
|
30 | if (!response.ok) { |
31 | throw new Error(`${response.status} ${await response.text()}`) |
32 | } |
33 |
|
34 | return await response.json() |
35 | } |
36 |
|