Edits history of script submission #23429 for ' Enroll Contact in Workflow (hubspot)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Enroll Contact in Workflow
     * Enroll a contact, by email address, into a workflow. The workflow must be turned on. Requires the automation scope and a Professional or Enterprise subscription.
     */
    export async function main(
      auth: RT.Hubspot,
      workflow_id: string,
      contact_email: string
    ) {
      const response = await fetch(
        `https://api.hubapi.com/automation/v2/workflows/${workflow_id}/enrollments/contacts/${encodeURIComponent(contact_email)}`,
        {
          method: "POST",
          headers: {
            Authorization: `Bearer ${auth.token}`,
            Accept: "application/json",
          },
        }
      )
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
      if (response.status === 204) return { success: true }
    
      return await response.json()
    }
    

    Submitted by hugo989 5 hours ago