0

Lists the phone number blocks jobs

by
Published Apr 8, 2025
Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Lists the phone number blocks jobs
7
 *
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	filter_type_: 'delete_phone_number_block' | undefined,
12
	filter_status_: 'pending' | 'in_progress' | 'completed' | 'failed' | undefined,
13
	page_number_: string | undefined,
14
	page_size_: string | undefined,
15
	sort: 'created_at' | undefined
16
) {
17
	const url = new URL(`https://api.telnyx.com/v2/phone_number_blocks/jobs`)
18
	for (const [k, v] of [
19
		['filter[type]', filter_type_],
20
		['filter[status]', filter_status_],
21
		['page[number]', page_number_],
22
		['page[size]', page_size_],
23
		['sort', sort]
24
	]) {
25
		if (v !== undefined && v !== '' && k !== undefined) {
26
			url.searchParams.append(k, v)
27
		}
28
	}
29
	const response = await fetch(url, {
30
		method: 'GET',
31
		headers: {
32
			Authorization: 'Bearer ' + auth.apiKey
33
		},
34
		body: undefined
35
	})
36
	if (!response.ok) {
37
		const text = await response.text()
38
		throw new Error(`${response.status} ${text}`)
39
	}
40
	return await response.json()
41
}
42