1 | |
2 | type Telnyx = { |
3 | apiKey: string |
4 | } |
5 | |
6 | * List all porting phone numbers |
7 | * Returns a list of your porting phone numbers. |
8 | */ |
9 | export async function main( |
10 | auth: Telnyx, |
11 | page_number_: string | undefined, |
12 | page_size_: string | undefined, |
13 | filter_porting_order_id_: string | undefined, |
14 | filter_porting_order_id__in___: string | undefined, |
15 | filter_support_key__eq_: string | undefined, |
16 | filter_support_key__in___: string | undefined, |
17 | filter_phone_number_: string | undefined, |
18 | filter_phone_number__in___: string | undefined, |
19 | filter_porting_order_status_: |
20 | | 'draft' |
21 | | 'in-process' |
22 | | 'submitted' |
23 | | 'exception' |
24 | | 'foc-date-confirmed' |
25 | | 'cancel-pending' |
26 | | 'ported' |
27 | | 'cancelled' |
28 | | undefined, |
29 | filter_activation_status_: |
30 | | 'New' |
31 | | 'Pending' |
32 | | 'Conflict' |
33 | | 'Cancel Pending' |
34 | | 'Failed' |
35 | | 'Concurred' |
36 | | 'Activate RDY' |
37 | | 'Disconnect Pending' |
38 | | 'Concurrence Sent' |
39 | | 'Old' |
40 | | 'Sending' |
41 | | 'Active' |
42 | | 'Cancelled' |
43 | | undefined, |
44 | filter_portability_status_: 'pending' | 'confirmed' | 'provisional' | undefined |
45 | ) { |
46 | const url = new URL(`https://api.telnyx.com/v2/porting_phone_numbers`) |
47 | for (const [k, v] of [ |
48 | ['page[number]', page_number_], |
49 | ['page[size]', page_size_], |
50 | ['filter[porting_order_id]', filter_porting_order_id_], |
51 | ['filter[porting_order_id][in][]', filter_porting_order_id__in___], |
52 | ['filter[support_key][eq]', filter_support_key__eq_], |
53 | ['filter[support_key][in][]', filter_support_key__in___], |
54 | ['filter[phone_number]', filter_phone_number_], |
55 | ['filter[phone_number][in][]', filter_phone_number__in___], |
56 | ['filter[porting_order_status]', filter_porting_order_status_], |
57 | ['filter[activation_status]', filter_activation_status_], |
58 | ['filter[portability_status]', filter_portability_status_] |
59 | ]) { |
60 | if (v !== undefined && v !== '' && k !== undefined) { |
61 | url.searchParams.append(k, v) |
62 | } |
63 | } |
64 | const response = await fetch(url, { |
65 | method: 'GET', |
66 | headers: { |
67 | Authorization: 'Bearer ' + auth.apiKey |
68 | }, |
69 | body: undefined |
70 | }) |
71 | if (!response.ok) { |
72 | const text = await response.text() |
73 | throw new Error(`${response.status} ${text}`) |
74 | } |
75 | return await response.json() |
76 | } |
77 |
|