0

Create a porting related report

by
Published Apr 8, 2025

Generate reports about porting operations.

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Create a porting related report
7
 * Generate reports about porting operations.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	body: {
12
		report_type: 'export_porting_orders_csv'
13
		params: {
14
			filters: {
15
				status__in?:
16
					| 'draft'
17
					| 'in-process'
18
					| 'submitted'
19
					| 'exception'
20
					| 'foc-date-confirmed'
21
					| 'cancel-pending'
22
					| 'ported'
23
					| 'cancelled'[]
24
				customer_reference__in?: string[]
25
				created_at__lt?: string
26
				created_at__gt?: string
27
			}
28
		}
29
	}
30
) {
31
	const url = new URL(`https://api.telnyx.com/v2/porting/reports`)
32

33
	const response = await fetch(url, {
34
		method: 'POST',
35
		headers: {
36
			'Content-Type': 'application/json',
37
			Authorization: 'Bearer ' + auth.apiKey
38
		},
39
		body: JSON.stringify(body)
40
	})
41
	if (!response.ok) {
42
		const text = await response.text()
43
		throw new Error(`${response.status} ${text}`)
44
	}
45
	return await response.json()
46
}
47