0

Lists keys

by
Published Oct 17, 2025

Lists all keys for this consumer.

Script zuplo Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zuplo = {
3
	apiKey: string
4
}
5
/**
6
 * Lists keys
7
 * Lists all keys for this consumer.
8
 */
9
export async function main(
10
	auth: Zuplo,
11
	accountName: string,
12
	bucketName: string,
13
	consumerName: string,
14
	limit: string | undefined,
15
	offset: string | undefined,
16
	key_format: 'none' | 'visible' | 'masked' | undefined
17
) {
18
	const url = new URL(
19
		`https://dev.zuplo.com/v1/accounts/${accountName}/key-buckets/${bucketName}/consumers/${consumerName}/keys`
20
	)
21
	for (const [k, v] of [
22
		['limit', limit],
23
		['offset', offset],
24
		['key-format', key_format]
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