0

Search detail records

by
Published Apr 8, 2025

Search for any detail record across the Telnyx Platform

Script telnyx Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Telnyx = {
3
	apiKey: string
4
}
5
/**
6
 * Search detail records
7
 * Search for any detail record across the Telnyx Platform
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	filter_record_type_:
12
		| 'ai-voice-assistant'
13
		| 'amd'
14
		| 'call-control'
15
		| 'conference'
16
		| 'conference-participant'
17
		| 'embedding'
18
		| 'fax'
19
		| 'inference'
20
		| 'inference-speech-to-text'
21
		| 'media_storage'
22
		| 'media-streaming'
23
		| 'messaging'
24
		| 'noise-suppression'
25
		| 'recording'
26
		| 'sip-trunking'
27
		| 'siprec-client'
28
		| 'stt'
29
		| 'tts'
30
		| 'verify'
31
		| 'webrtc'
32
		| 'wireless'
33
		| undefined,
34
	filter_date_range_:
35
		| 'yesterday'
36
		| 'today'
37
		| 'tomorrow'
38
		| 'last_week'
39
		| 'this_week'
40
		| 'next_week'
41
		| 'last_month'
42
		| 'this_month'
43
		| 'next_month'
44
		| undefined,
45
	filter: string | undefined,
46
	page_number_: string | undefined,
47
	page_size_: string | undefined,
48
	sort: string | undefined
49
) {
50
	const url = new URL(`https://api.telnyx.com/v2/detail_records`)
51
	for (const [k, v] of [
52
		['filter[record_type]', filter_record_type_],
53
		['filter[date_range]', filter_date_range_],
54
		['filter', filter],
55
		['page[number]', page_number_],
56
		['page[size]', page_size_],
57
		['sort', sort]
58
	]) {
59
		if (v !== undefined && v !== '' && k !== undefined) {
60
			url.searchParams.append(k, v)
61
		}
62
	}
63
	const response = await fetch(url, {
64
		method: 'GET',
65
		headers: {
66
			Authorization: 'Bearer ' + auth.apiKey
67
		},
68
		body: undefined
69
	})
70
	if (!response.ok) {
71
		const text = await response.text()
72
		throw new Error(`${response.status} ${text}`)
73
	}
74
	return await response.json()
75
}
76