Update Opportunity

Updates a new opportunity in Apollo.io. [See the documentation](https://apolloio.github.io/apollo-api-docs/?shell#update-opportunity)

Script apollo Verified

by hugo697 ยท 8/26/2024

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 650 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