0

List Forms

by
Published today

List the account's marketing forms.

Script hubspot Verified

The script

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

3
/**
4
 * List Forms
5
 * List the account's marketing forms. Requires the forms scope.
6
 */
7
export async function main(
8
  auth: RT.Hubspot,
9
  limit: number | undefined,
10
  after: string | undefined,
11
  archived: boolean | undefined,
12
  form_types:
13
    | ("hubspot" | "captured" | "flow" | "blog_comment" | "all")[]
14
    | undefined
15
) {
16
  const url = new URL(`https://api.hubapi.com/marketing/v3/forms`)
17
  if (limit != null) url.searchParams.append("limit", String(limit))
18
  if (after != null && after !== "") url.searchParams.append("after", after)
19
  if (archived) url.searchParams.append("archived", String(archived))
20
  if (form_types?.length)
21
    url.searchParams.append("formTypes", form_types.join(","))
22

23
  const response = await fetch(url, {
24
    headers: {
25
      Authorization: `Bearer ${auth.token}`,
26
      Accept: "application/json",
27
    },
28
  })
29

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

34
  return await response.json()
35
}
36