0

Update Page

by
Published today

Update a website page or landing page.

Script hubspot Verified

The script

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

3
/**
4
 * Update Page
5
 * Update a website page or landing page. Only the fields you pass change. Requires the content scope.
6
 */
7
export async function main(
8
  auth: RT.Hubspot,
9
  page_type: "site-pages" | "landing-pages",
10
  page_id: string,
11
  body: { [key: string]: any }
12
) {
13
  const url = new URL(
14
    `https://api.hubapi.com/cms/v3/pages/${page_type}/${page_id}`
15
  )
16

17
  const response = await fetch(url, {
18
    method: "PATCH",
19
    headers: {
20
      Authorization: `Bearer ${auth.token}`,
21
      "Content-Type": "application/json",
22
      Accept: "application/json",
23
    },
24
    body: JSON.stringify(body),
25
  })
26

27
  if (!response.ok) {
28
    throw new Error(`${response.status} ${await response.text()}`)
29
  }
30

31
  return await response.json()
32
}
33