1 | |
2 | type Telnyx = { |
3 | apiKey: string |
4 | } |
5 | |
6 | * Lists accounts managed by the current user. |
7 | * Lists the accounts managed by the current user. Users need to be explictly approved by Telnyx in order to become manager accounts. |
8 | */ |
9 | export async function main( |
10 | auth: Telnyx, |
11 | page_number_: string | undefined, |
12 | page_size_: string | undefined, |
13 | filter_email__contains_: string | undefined, |
14 | filter_email__eq_: string | undefined, |
15 | filter_organization_name__contains_: string | undefined, |
16 | filter_organization_name__eq_: string | undefined, |
17 | sort: 'asc' | 'desc' | undefined, |
18 | include_cancelled_accounts: string | undefined |
19 | ) { |
20 | const url = new URL(`https://api.telnyx.com/v2/managed_accounts`) |
21 | for (const [k, v] of [ |
22 | ['page[number]', page_number_], |
23 | ['page[size]', page_size_], |
24 | ['filter[email][contains]', filter_email__contains_], |
25 | ['filter[email][eq]', filter_email__eq_], |
26 | ['filter[organization_name][contains]', filter_organization_name__contains_], |
27 | ['filter[organization_name][eq]', filter_organization_name__eq_], |
28 | ['sort', sort], |
29 | ['include_cancelled_accounts', include_cancelled_accounts] |
30 | ]) { |
31 | if (v !== undefined && v !== '' && k !== undefined) { |
32 | url.searchParams.append(k, v) |
33 | } |
34 | } |
35 | const response = await fetch(url, { |
36 | method: 'GET', |
37 | headers: { |
38 | Authorization: 'Bearer ' + auth.apiKey |
39 | }, |
40 | body: undefined |
41 | }) |
42 | if (!response.ok) { |
43 | const text = await response.text() |
44 | throw new Error(`${response.status} ${text}`) |
45 | } |
46 | return await response.json() |
47 | } |
48 |
|