0

Api keys partial update

by
Published Apr 8, 2025

Updates an API key.

Script ultravox Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Ultravox = {
3
  apiKey: string;
4
};
5
/**
6
 * Api keys partial update
7
 * Updates an API key.
8
 */
9
export async function main(
10
  auth: Ultravox,
11
  api_key_prefix: string,
12
  body: {
13
    prefix?: string;
14
    created?: string;
15
    creator?: string;
16
    name?: string;
17
    expiryDate?: string;
18
    revoked?: false | true;
19
  },
20
) {
21
  const url = new URL(`https://api.ultravox.ai/api/api_keys/${api_key_prefix}`);
22

23
  const response = await fetch(url, {
24
    method: "PATCH",
25
    headers: {
26
      "Content-Type": "application/json",
27
      "X-API-Key": auth.apiKey,
28
    },
29
    body: JSON.stringify(body),
30
  });
31
  if (!response.ok) {
32
    const text = await response.text();
33
    throw new Error(`${response.status} ${text}`);
34
  }
35
  return await response.json();
36
}
37