Edits history of script submission #23416 for ' Create Contact Flow (hubspot)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Create Contact Flow
     * 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.
     */
    export async function main(auth: RT.Hubspot, body: { [key: string]: any }) {
      const response = await fetch("https://api.hubapi.com/automation/v4/flows", {
        method: "POST",
        headers: {
          Authorization: `Bearer ${auth.token}`,
          "Content-Type": "application/json",
          Accept: "application/json",
        },
        body: JSON.stringify({ type: "CONTACT_FLOW", ...body }),
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 5 hours ago