0

Create Marketing Email

by
Published today

Create a marketing email draft.

Script hubspot Verified

The script

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

3
/**
4
 * Create Marketing Email
5
 * Create a marketing email draft. `body` is a HubSpot marketing email object; the minimum is {"name": "..."} and common fields are subject, templatePath, from {fromName, replyTo}, to {contactLists}, content. Requires the content scope.
6
 */
7
export async function main(auth: RT.Hubspot, body: { [key: string]: any }) {
8
  const url = new URL(`https://api.hubapi.com/marketing/v3/emails`)
9

10
  const response = await fetch(url, {
11
    method: "POST",
12
    headers: {
13
      Authorization: `Bearer ${auth.token}`,
14
      "Content-Type": "application/json",
15
      Accept: "application/json",
16
    },
17
    body: JSON.stringify(body),
18
  })
19

20
  if (!response.ok) {
21
    throw new Error(`${response.status} ${await response.text()}`)
22
  }
23

24
  return await response.json()
25
}
26