1 | type Apollo = { |
2 | apiKey: string; |
3 | }; |
4 |
|
5 | export async function main( |
6 | resource: Apollo, |
7 | params: { |
8 | search: string; |
9 | accountStageId?: string[]; |
10 | sortByField?: "account_last_activity_date" | "account_created_at"; |
11 | sortAscending?: boolean; |
12 | } |
13 | ) { |
14 | const endpoint = "https://api.apollo.io/v1/accounts/search"; |
15 | const body = { |
16 | q_organization_name: params.search, |
17 | account_stage_ids: params.accountStageId, |
18 | sort_by_field: params.sortByField, |
19 | sort_ascending: params.sortAscending, |
20 | }; |
21 |
|
22 | const response = await fetch(endpoint, { |
23 | method: "POST", |
24 | headers: { |
25 | "Content-Type": "application/json", |
26 | "Cache-Control": "no-cache", |
27 | "X-Api-Key": resource.apiKey, |
28 | }, |
29 | body: JSON.stringify(body), |
30 | }); |
31 |
|
32 | if (!response.ok) { |
33 | throw new Error(`HTTP error! status: ${response.status}`); |
34 | } |
35 |
|
36 | const data = await response.json(); |
37 |
|
38 | return data.accounts; |
39 | } |
40 |
|