1 | |
2 |
|
3 | |
4 | * List Accounts |
5 | * Lists accounts with optional filters (name, domain, updatedAt range like "2024-01-01..inf") and cursor pagination. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Outreach, |
9 | filter_name: string | undefined, |
10 | filter_domain: string | undefined, |
11 | filter_updated_at: string | undefined, |
12 | sort: string | undefined, |
13 | page_size: number | undefined, |
14 | page_after: string | undefined |
15 | ) { |
16 | const url = new URL("https://api.outreach.io/api/v2/accounts") |
17 | if (filter_name !== undefined && filter_name !== "") { |
18 | url.searchParams.append("filter[name]", filter_name) |
19 | } |
20 | if (filter_domain !== undefined && filter_domain !== "") { |
21 | url.searchParams.append("filter[domain]", filter_domain) |
22 | } |
23 | if (filter_updated_at !== undefined && filter_updated_at !== "") { |
24 | url.searchParams.append("filter[updatedAt]", filter_updated_at) |
25 | } |
26 | if (sort !== undefined && sort !== "") { |
27 | url.searchParams.append("sort", sort) |
28 | } |
29 | if (page_size !== undefined) { |
30 | url.searchParams.append("page[size]", String(page_size)) |
31 | } |
32 | if (page_after !== undefined && page_after !== "") { |
33 | url.searchParams.append("page[after]", page_after) |
34 | } |
35 |
|
36 | const response = await fetch(url, { |
37 | headers: { |
38 | Authorization: `Bearer ${auth.token}`, |
39 | Accept: "application/vnd.api+json", |
40 | }, |
41 | }) |
42 |
|
43 | if (!response.ok) { |
44 | throw new Error(`${response.status} ${await response.text()}`) |
45 | } |
46 |
|
47 | return await response.json() |
48 | } |
49 |
|