0
Create Contact
One script reply has been approved by the moderators Verified

Creates a new contact in Apollo.io. See the documentation

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

5
export async function main(
6
  resource: Apollo,
7
  body: {
8
    first_name: string;
9
    last_name: string;
10
    title: string;
11
    organization_name: string;
12
    account_id?: string;
13
    email?: string;
14
    label_names?: string[];
15
    present_raw_address?: string;
16
    direct_phone?: string;
17
    corporate_phone?: string;
18
    mobile_phone?: string;
19
    home_phone?: string;
20
    other_phone?: string;
21
  }
22
) {
23
  const endpoint = "https://api.apollo.io/v1/contacts";
24

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

35
  if (!response.ok) {
36
    throw new Error(`HTTP error! status: ${response.status}`);
37
  }
38

39
  const data = await response.json();
40

41
  return data.contact;
42
}
43