0

Updates a consumer

by
Published Oct 17, 2025

Update the consumer with the matching consumer name.

Script zuplo Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zuplo = {
3
	apiKey: string
4
}
5
/**
6
 * Updates a consumer
7
 * Update the consumer with the matching consumer name.
8
 */
9
export async function main(
10
	auth: Zuplo,
11
	accountName: string,
12
	bucketName: string,
13
	consumerName: string,
14
	tag: string | undefined,
15
	body: { description?: string; tags?: {}; metadata?: {} }
16
) {
17
	const url = new URL(
18
		`https://dev.zuplo.com/v1/accounts/${accountName}/key-buckets/${bucketName}/consumers/${consumerName}`
19
	)
20
	for (const [k, v] of [['tag', tag]]) {
21
		if (v !== undefined && v !== '' && k !== undefined) {
22
			url.searchParams.append(k, v)
23
		}
24
	}
25
	const response = await fetch(url, {
26
		method: 'PATCH',
27
		headers: {
28
			'Content-Type': 'application/json',
29
			Authorization: 'Bearer ' + auth.apiKey
30
		},
31
		body: JSON.stringify(body)
32
	})
33
	if (!response.ok) {
34
		const text = await response.text()
35
		throw new Error(`${response.status} ${text}`)
36
	}
37
	return await response.json()
38
}
39