Delete key
One script reply has been approved by the moderators Verified

Deletes API key. Only a key not used to authenticate the active request can be deleted.

Created by hugo697 141 days ago
Submitted by hugo697 Bun
Verified 141 days ago
1
//native
2
type Clickhouse = {
3
  username: string;
4
  password: string;
5
  host: string;
6
};
7
/**
8
 * Delete key
9
 * Deletes API key. Only a key not used to authenticate the active request can be deleted.
10
 */
11
export async function main(
12
  auth: Clickhouse,
13
  organizationId: string,
14
  keyId: string
15
) {
16
  const url = new URL(
17
    `https://api.clickhouse.cloud/v1/organizations/${organizationId}/keys/${keyId}`
18
  );
19

20
  const response = await fetch(url, {
21
    method: "DELETE",
22
    headers: {
23
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
24
    },
25
    body: undefined,
26
  });
27
  if (!response.ok) {
28
    const text = await response.text();
29
    throw new Error(`${response.status} ${text}`);
30
  }
31
  return await response.json();
32
}
33