0

Clone Marketing Email

by
Published today

Create a copy of an existing marketing email.

Script hubspot Verified

The script

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

3
/**
4
 * Clone Marketing Email
5
 * Create a copy of an existing marketing email. Requires the content scope.
6
 */
7
export async function main(
8
  auth: RT.Hubspot,
9
  email_id: string,
10
  clone_name: string | undefined,
11
  language: string | undefined
12
) {
13
  const url = new URL(`https://api.hubapi.com/marketing/v3/emails/clone`)
14

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

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

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

34
  return await response.json()
35
}
36