Edits history of script submission #14628 for ' Delete key (clickhouse)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Clickhouse = {
      username: string;
      password: string;
      host: string;
    };
    /**
     * Delete key
     * Deletes API key. Only a key not used to authenticate the active request can be deleted.
     */
    export async function main(
      auth: Clickhouse,
      organizationId: string,
      keyId: string
    ) {
      const url = new URL(
        `https://api.clickhouse.cloud/v1/organizations/${organizationId}/keys/${keyId}`
      );
    
      const response = await fetch(url, {
        method: "DELETE",
        headers: {
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago