0

List Pages

by
Published today

List website pages or landing pages, optionally filtered by creation/update date (ISO 8601).

Script hubspot Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 4 hours ago
1
//native
2

3
/**
4
 * List Pages
5
 * List website pages or landing pages, optionally filtered by creation/update date (ISO 8601). Requires the content scope.
6
 */
7
export async function main(
8
  auth: RT.Hubspot,
9
  page_type: "site-pages" | "landing-pages",
10
  limit: number | undefined,
11
  after: string | undefined,
12
  created_after: string | undefined,
13
  created_before: string | undefined,
14
  updated_after: string | undefined,
15
  updated_before: string | undefined,
16
  archived: boolean | undefined,
17
  sort: string | undefined
18
) {
19
  const url = new URL(`https://api.hubapi.com/cms/v3/pages/${page_type}`)
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 (archived) url.searchParams.append("archived", String(archived))
31
  if (sort != null && sort !== "") url.searchParams.append("sort", sort)
32

33
  const response = await fetch(url, {
34
    headers: {
35
      Authorization: `Bearer ${auth.token}`,
36
      Accept: "application/json",
37
    },
38
  })
39

40
  if (!response.ok) {
41
    throw new Error(`${response.status} ${await response.text()}`)
42
  }
43

44
  return await response.json()
45
}
46