0

List additional documents

by
Published Apr 8, 2025

Returns a list of additional documents for a porting order.

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * List additional documents
7
 * Returns a list of additional documents for a porting order.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	id: string,
12
	page_number_: string | undefined,
13
	page_size_: string | undefined,
14
	filter_document_type_: 'loa' | 'invoice' | 'csr' | 'other' | undefined,
15
	filter_document_type__in___: string | undefined,
16
	sort__: 'created_at' | '-created_at' | undefined
17
) {
18
	const url = new URL(`https://api.telnyx.com/v2/porting_orders/${id}/additional_documents`)
19
	for (const [k, v] of [
20
		['page[number]', page_number_],
21
		['page[size]', page_size_],
22
		['filter[document_type]', filter_document_type_],
23
		['filter[document_type][in][]', filter_document_type__in___],
24
		['sort[]', sort__]
25
	]) {
26
		if (v !== undefined && v !== '' && k !== undefined) {
27
			url.searchParams.append(k, v)
28
		}
29
	}
30
	const response = await fetch(url, {
31
		method: 'GET',
32
		headers: {
33
			Authorization: 'Bearer ' + auth.apiKey
34
		},
35
		body: undefined
36
	})
37
	if (!response.ok) {
38
		const text = await response.text()
39
		throw new Error(`${response.status} ${text}`)
40
	}
41
	return await response.json()
42
}
43