0

Update an API key

by
Published Nov 5, 2024

Update an API key such as the roles attached to the key.

Script vectara Verified

The script

Submitted by hugo697 Bun
Verified 581 days ago
1
//native
2
type Vectara = {
3
	apiKey: string
4
}
5
/**
6
 * Update an API key
7
 * Update an API key such as the roles attached to the key.
8
 */
9
export async function main(auth: Vectara, api_key_id: string, body: { enabled?: false | true }) {
10
	const url = new URL(`https://api.vectara.io/v2/api_keys/${api_key_id}`)
11

12
	const response = await fetch(url, {
13
		method: 'PATCH',
14
		headers: {
15
			'Content-Type': 'application/json',
16
			'x-api-key': auth.apiKey
17
		},
18
		body: JSON.stringify(body)
19
	})
20
	if (!response.ok) {
21
		const text = await response.text()
22
		throw new Error(`${response.status} ${text}`)
23
	}
24
	return await response.json()
25
}
26