0
Add Contacts to Sequence
One script reply has been approved by the moderators Verified

Adds one or more contacts to a sequence in Apollo.io. See the documentation

Created by hugo697 25 days ago Viewed 10 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 25 days ago
1
type Apollo = {
2
  apiKey: string;
3
};
4

5
export async function main(
6
  resource: Apollo,
7
  sequenceId: string,
8
  contactIds: string[],
9
  emailAccountId: string,
10
  options?: {
11
    sequenceNoEmail?: boolean;
12
    sequenceActiveInOtherCampaigns?: boolean;
13
    sequenceFinishedInOtherCampaigns?: boolean;
14
  }
15
) {
16
  const endpoint = `https://api.apollo.io/v1/emailer_campaigns/${sequenceId}/add_contact_ids`;
17
  const body = {
18
    async: false,
19
    contact_ids: contactIds,
20
    emailer_campaign_id: sequenceId,
21
    send_email_from_email_account_id: emailAccountId,
22
    sequence_no_email: options?.sequenceNoEmail,
23
    sequence_active_in_other_campaigns: options?.sequenceActiveInOtherCampaigns,
24
    sequence_finished_in_other_campaigns:
25
      options?.sequenceFinishedInOtherCampaigns,
26
  };
27

28
  const response = await fetch(endpoint, {
29
    method: "POST",
30
    headers: {
31
      "Content-Type": "application/json",
32
      "Cache-Control": "no-cache",
33
      "X-Api-Key": resource.apiKey,
34
    },
35
    body: JSON.stringify(body),
36
  });
37

38
  if (!response.ok) {
39
    throw new Error(`HTTP error! status: ${response.status}`);
40
  }
41

42
  const data = await response.json();
43

44
  return data.contacts;
45
}
46