//native
/**
* Create Workflow
* Create a contact-based workflow with the legacy v3 API. `actions` is a list of workflow action objects, e.g. [{"type": "DELAY", "delayMillis": 3600000}]. The workflow is created turned off unless `enabled` is set. Requires the automation scope and a Professional or Enterprise subscription.
*/
export async function main(
auth: RT.Hubspot,
name: string,
type: "DRIP_DELAY" | "STATIC_ANCHOR" | "PROPERTY_ANCHOR",
actions: { [key: string]: any }[] | undefined,
enabled: boolean | undefined
) {
const url = new URL(`https://api.hubapi.com/automation/v3/workflows`)
const body: { [key: string]: any } = {}
body.name = name
body.type = type
if (actions?.length) body.actions = actions
if (enabled) body.enabled = enabled
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: `Bearer ${auth.token}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify(body),
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 4 hours ago