1 | |
2 |
|
3 | |
4 | * Enroll Contact in Sequence |
5 | * Enroll a contact in a sales sequence, sent from a connected inbox. `user_id` is the HubSpot user who owns the enrollment, `sender_email` one of their connected inboxes. Requires automation.sequences.enrollments.write (Sales or Service Hub Professional or Enterprise). |
6 | */ |
7 | export async function main( |
8 | auth: RT.Hubspot, |
9 | user_id: string, |
10 | sequence_id: string, |
11 | contact_id: string, |
12 | sender_email: string, |
13 | sender_alias_address: string | undefined |
14 | ) { |
15 | const url = new URL( |
16 | `https://api.hubapi.com/automation/v4/sequences/enrollments` |
17 | ) |
18 | url.searchParams.append("userId", user_id) |
19 |
|
20 | const body: { [key: string]: any } = {} |
21 | body.sequenceId = sequence_id |
22 | body.contactId = contact_id |
23 | body.senderEmail = sender_email |
24 | if (sender_alias_address != null && sender_alias_address !== "") |
25 | body.senderAliasAddress = sender_alias_address |
26 |
|
27 | const response = await fetch(url, { |
28 | method: "POST", |
29 | headers: { |
30 | Authorization: `Bearer ${auth.token}`, |
31 | "Content-Type": "application/json", |
32 | Accept: "application/json", |
33 | }, |
34 | body: JSON.stringify(body), |
35 | }) |
36 |
|
37 | if (!response.ok) { |
38 | throw new Error(`${response.status} ${await response.text()}`) |
39 | } |
40 |
|
41 | return await response.json() |
42 | } |
43 |
|