1 | |
2 | type Telnyx = { |
3 | apiKey: string |
4 | } |
5 | |
6 | * List Verification Requests |
7 | * Get a list of previously-submitted tollfree verification requests |
8 | */ |
9 | export async function main( |
10 | auth: Telnyx, |
11 | page: string | undefined, |
12 | page_size: string | undefined, |
13 | date_start: string | undefined, |
14 | date_end: string | undefined, |
15 | status: |
16 | | 'Verified' |
17 | | 'Rejected' |
18 | | 'Waiting For Vendor' |
19 | | 'Waiting For Customer' |
20 | | 'In Progress' |
21 | | undefined, |
22 | phone_number: string | undefined |
23 | ) { |
24 | const url = new URL(`https://api.telnyx.com/v2/messaging_tollfree/verification/requests`) |
25 | for (const [k, v] of [ |
26 | ['page', page], |
27 | ['page_size', page_size], |
28 | ['date_start', date_start], |
29 | ['date_end', date_end], |
30 | ['status', status], |
31 | ['phone_number', phone_number] |
32 | ]) { |
33 | if (v !== undefined && v !== '' && k !== undefined) { |
34 | url.searchParams.append(k, v) |
35 | } |
36 | } |
37 | const response = await fetch(url, { |
38 | method: 'GET', |
39 | headers: { |
40 | Authorization: 'Bearer ' + auth.apiKey |
41 | }, |
42 | body: undefined |
43 | }) |
44 | if (!response.ok) { |
45 | const text = await response.text() |
46 | throw new Error(`${response.status} ${text}`) |
47 | } |
48 | return await response.json() |
49 | } |
50 |
|