1 | |
2 |
|
3 | |
4 | * List Blog Posts |
5 | * List blog posts, optionally filtered by creation/update date (ISO 8601). 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 | archived: boolean | undefined, |
16 | sort: string | undefined |
17 | ) { |
18 | const url = new URL(`https://api.hubapi.com/cms/v3/blogs/posts`) |
19 | if (limit != null) url.searchParams.append("limit", String(limit)) |
20 | if (after != null && after !== "") url.searchParams.append("after", after) |
21 | if (created_after != null && created_after !== "") |
22 | url.searchParams.append("createdAfter", created_after) |
23 | if (created_before != null && created_before !== "") |
24 | url.searchParams.append("createdBefore", created_before) |
25 | if (updated_after != null && updated_after !== "") |
26 | url.searchParams.append("updatedAfter", updated_after) |
27 | if (updated_before != null && updated_before !== "") |
28 | url.searchParams.append("updatedBefore", updated_before) |
29 | if (archived) url.searchParams.append("archived", String(archived)) |
30 | if (sort != null && sort !== "") url.searchParams.append("sort", sort) |
31 |
|
32 | const response = await fetch(url, { |
33 | headers: { |
34 | Authorization: `Bearer ${auth.token}`, |
35 | Accept: "application/json", |
36 | }, |
37 | }) |
38 |
|
39 | if (!response.ok) { |
40 | throw new Error(`${response.status} ${await response.text()}`) |
41 | } |
42 |
|
43 | return await response.json() |
44 | } |
45 |
|