0

Create Form

by
Published today

Create a marketing form.

Script hubspot Verified

The script

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

3
/**
4
 * Create Form
5
 * Create a marketing form. `body` is a HubSpot form definition; the minimum is {"formType": "hubspot", "name": "...", "createdAt": "<ISO date>", "fieldGroups": [], "configuration": {}, "displayOptions": {}, "legalConsentOptions": {"type": "none"}}. Requires the forms 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/forms`)
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