1 | |
2 | type Telnyx = { |
3 | apiKey: string |
4 | } |
5 | |
6 | * List requirement groups |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Telnyx, |
11 | filter_country_code_: string | undefined, |
12 | filter_phone_number_type_: |
13 | | 'local' |
14 | | 'toll_free' |
15 | | 'mobile' |
16 | | 'national' |
17 | | 'shared_cost' |
18 | | undefined, |
19 | filter_action_: 'ordering' | 'porting' | 'action' | undefined, |
20 | filter_status_: 'approved' | 'unapproved' | 'pending-approval' | 'declined' | undefined, |
21 | filter_customer_reference_: string | undefined |
22 | ) { |
23 | const url = new URL(`https://api.telnyx.com/v2/requirement_groups`) |
24 | for (const [k, v] of [ |
25 | ['filter[country_code]', filter_country_code_], |
26 | ['filter[phone_number_type]', filter_phone_number_type_], |
27 | ['filter[action]', filter_action_], |
28 | ['filter[status]', filter_status_], |
29 | ['filter[customer_reference]', filter_customer_reference_] |
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 |
|