1 | |
2 | type Telnyx = { |
3 | apiKey: string |
4 | } |
5 | |
6 | * Get all outbound voice profiles |
7 | * Get all outbound voice profiles belonging to the user that match the given filters. |
8 | */ |
9 | export async function main( |
10 | auth: Telnyx, |
11 | page_number_: string | undefined, |
12 | page_size_: string | undefined, |
13 | filter_name__contains_: string | undefined, |
14 | sort: |
15 | | 'enabled' |
16 | | '-enabled' |
17 | | 'created_at' |
18 | | '-created_at' |
19 | | 'name' |
20 | | '-name' |
21 | | 'service_plan' |
22 | | '-service_plan' |
23 | | 'traffic_type' |
24 | | '-traffic_type' |
25 | | 'usage_payment_method' |
26 | | '-usage_payment_method' |
27 | | undefined |
28 | ) { |
29 | const url = new URL(`https://api.telnyx.com/v2/outbound_voice_profiles`) |
30 | for (const [k, v] of [ |
31 | ['page[number]', page_number_], |
32 | ['page[size]', page_size_], |
33 | ['filter[name][contains]', filter_name__contains_], |
34 | ['sort', sort] |
35 | ]) { |
36 | if (v !== undefined && v !== '' && k !== undefined) { |
37 | url.searchParams.append(k, v) |
38 | } |
39 | } |
40 | const response = await fetch(url, { |
41 | method: 'GET', |
42 | headers: { |
43 | Authorization: 'Bearer ' + auth.apiKey |
44 | }, |
45 | body: undefined |
46 | }) |
47 | if (!response.ok) { |
48 | const text = await response.text() |
49 | throw new Error(`${response.status} ${text}`) |
50 | } |
51 | return await response.json() |
52 | } |
53 |
|