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

Updates an existing contact in Apollo.io. See the documentation

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

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

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

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

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

42
  return data.contact;
43
}
44