0
Search For Contacts
One script reply has been approved by the moderators Verified

Search for contacts 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
  params: {
8
    search: string;
9
    contactStageId?: string[];
10
    sortByField?:
11
      | "contact_last_activity_date"
12
      | "contact_email_last_opened_at"
13
      | "contact_email_last_clicked_at"
14
      | "contact_created_at"
15
      | "contact_updated_at";
16

17
    sortAscending?: boolean;
18
  }
19
) {
20
  const endpoint = "https://api.apollo.io/v1/contacts/search";
21
  const body = {
22
    q_keywords: params.search,
23
    contact_stage_ids: params.contactStageId,
24
    sort_by_field: params.sortByField,
25
    sort_ascending: params.sortAscending,
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