0

Gets an API key

by
Published Oct 17, 2025

Retrieves an API key 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
 * Gets an API key
7
 * Retrieves an API key for this consumer.
8
 */
9
export async function main(
10
	auth: Zuplo,
11
	accountName: string,
12
	bucketName: string,
13
	consumerName: string,
14
	keyId: string,
15
	key_format: 'none' | 'visible' | 'masked' | undefined,
16
	tag: string | undefined
17
) {
18
	const url = new URL(
19
		`https://dev.zuplo.com/v1/accounts/${accountName}/key-buckets/${bucketName}/consumers/${consumerName}/keys/${keyId}`
20
	)
21
	for (const [k, v] of [
22
		['key-format', key_format],
23
		['tag', tag]
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