1 | |
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 |
|