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

Deletes the service. The service must be in stopped state and is deleted asynchronously after this method call.

Created by hugo697 142 days ago Picked 1 time
Submitted by hugo697 Bun
Verified 142 days ago
1
//native
2
type Clickhouse = {
3
  username: string;
4
  password: string;
5
  host: string;
6
};
7
/**
8
 * Delete service
9
 * Deletes the service. The service must be in stopped state and is deleted asynchronously after this method call.
10
 */
11
export async function main(
12
  auth: Clickhouse,
13
  organizationId: string,
14
  serviceId: string
15
) {
16
  const url = new URL(
17
    `https://api.clickhouse.cloud/v1/organizations/${organizationId}/services/${serviceId}`
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