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

Updates a new opportunity in Apollo.io. See the documentation

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

5
export async function main(
6
  resource: Apollo,
7
  opportunityId: string,
8
  body: {
9
    owner_id?: string;
10
    name?: string;
11
    amount?: string;
12
    opportunity_stage_id?: string;
13
    closed_date?: string;
14
    account_id?: string;
15
  }
16
) {
17
  const endpoint = `https://api.apollo.io/v1/opportunities/${opportunityId}`;
18

19
  const response = await fetch(endpoint, {
20
    method: "PATCH",
21
    headers: {
22
      "Content-Type": "application/json",
23
      "Cache-Control": "no-cache",
24
      "X-Api-Key": resource.apiKey,
25
    },
26
    body: JSON.stringify(body),
27
  });
28

29
  if (!response.ok) {
30
    throw new Error(`HTTP error! status: ${response.status}`);
31
  }
32

33
  const data = await response.json();
34

35
  return data.opportunity;
36
}
37