0

Create Contact Flow

by
Published today

Create a contact-based workflow with the v4 flows API.

Script hubspot Verified

The script

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

3
/**
4
 * Create Contact Flow
5
 * Create a contact-based workflow with the v4 flows API. `body` is a flow definition; "type": "CONTACT_FLOW" is added for you. Common fields: name, isEnabled, flowType, startActionId, actions, enrollmentCriteria. Requires the automation scope and a Professional or Enterprise subscription.
6
 */
7
export async function main(auth: RT.Hubspot, body: { [key: string]: any }) {
8
  const response = await fetch("https://api.hubapi.com/automation/v4/flows", {
9
    method: "POST",
10
    headers: {
11
      Authorization: `Bearer ${auth.token}`,
12
      "Content-Type": "application/json",
13
      Accept: "application/json",
14
    },
15
    body: JSON.stringify({ type: "CONTACT_FLOW", ...body }),
16
  })
17

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

22
  return await response.json()
23
}
24