1 | |
2 |
|
3 | |
4 | * List Mailboxes |
5 | * Lists the org's sending mailboxes, optionally filtered by email address. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Outreach, |
9 | filter_email: string | undefined, |
10 | page_size: number | undefined, |
11 | page_after: string | undefined |
12 | ) { |
13 | const url = new URL("https://api.outreach.io/api/v2/mailboxes") |
14 | if (filter_email !== undefined && filter_email !== "") { |
15 | url.searchParams.append("filter[email]", filter_email) |
16 | } |
17 | if (page_size !== undefined) { |
18 | url.searchParams.append("page[size]", String(page_size)) |
19 | } |
20 | if (page_after !== undefined && page_after !== "") { |
21 | url.searchParams.append("page[after]", page_after) |
22 | } |
23 |
|
24 | const response = await fetch(url, { |
25 | headers: { |
26 | Authorization: `Bearer ${auth.token}`, |
27 | Accept: "application/vnd.api+json", |
28 | }, |
29 | }) |
30 |
|
31 | if (!response.ok) { |
32 | throw new Error(`${response.status} ${await response.text()}`) |
33 | } |
34 |
|
35 | return await response.json() |
36 | } |
37 |
|