0

List all SSO authentication providers

by
Published Apr 8, 2025

Returns a list of your SSO authentication providers.

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 all SSO authentication providers
7
 * Returns a list of your SSO authentication providers.
8
 */
9
export async function main(
10
	auth: Telnyx,
11
	page_number_: string | undefined,
12
	page_size_: string | undefined,
13
	sort:
14
		| 'name'
15
		| '-name'
16
		| 'short_name'
17
		| '-short_name'
18
		| 'active'
19
		| '-active'
20
		| 'created_at'
21
		| '-created_at'
22
		| 'updated_at'
23
		| '-updated_at'
24
		| undefined
25
) {
26
	const url = new URL(`https://api.telnyx.com/v2/authentication_providers`)
27
	for (const [k, v] of [
28
		['page[number]', page_number_],
29
		['page[size]', page_size_],
30
		['sort', sort]
31
	]) {
32
		if (v !== undefined && v !== '' && k !== undefined) {
33
			url.searchParams.append(k, v)
34
		}
35
	}
36
	const response = await fetch(url, {
37
		method: 'GET',
38
		headers: {
39
			Authorization: 'Bearer ' + auth.apiKey
40
		},
41
		body: undefined
42
	})
43
	if (!response.ok) {
44
		const text = await response.text()
45
		throw new Error(`${response.status} ${text}`)
46
	}
47
	return await response.json()
48
}
49