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

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

Created by hugo697 118 days ago Viewed 171 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
  body: {
8
    owner_id: string;
9
    name: string;
10
    amount: string;
11
    opportunity_stage_id: string;
12
    closed_date: string;
13
    account_id: string;
14
  }
15
) {
16
  const endpoint = "https://app.apollo.io/api/v1/opportunities";
17

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

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

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

34
  return data.opportunity;
35
}
36