0

Clone Page

by
Published today

Create a copy of 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
 * Clone Page
5
 * Create a copy of a website page or landing page. 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
  clone_name: string | undefined
12
) {
13
  const url = new URL(`https://api.hubapi.com/cms/v3/pages/${page_type}/clone`)
14

15
  const body: { [key: string]: any } = {}
16
  body.id = page_id
17
  if (clone_name != null && clone_name !== "") body.cloneName = clone_name
18

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

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

33
  return await response.json()
34
}
35