0

Delete Topic for a Kafka Cluster

by
Published Dec 20, 2024

To delete a single topic within a Kafka cluster, send a DELETE request to `/v2/databases/$DATABASE_ID/topics/$TOPIC_NAME`. A status of 204 will be given. This indicates that the request was processed successfully, but that no response body is needed.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Delete Topic for a Kafka Cluster
7
 * To delete a single topic within a Kafka cluster, send a DELETE request
8
to `/v2/databases/$DATABASE_ID/topics/$TOPIC_NAME`.
9

10
A status of 204 will be given. This indicates that the request was
11
processed successfully, but that no response body is needed.
12

13
 */
14
export async function main(
15
  auth: Digitalocean,
16
  database_cluster_uuid: string,
17
  topic_name: string,
18
) {
19
  const url = new URL(
20
    `https://api.digitalocean.com/v2/databases/${database_cluster_uuid}/topics/${topic_name}`,
21
  );
22

23
  const response = await fetch(url, {
24
    method: "DELETE",
25
    headers: {
26
      Authorization: "Bearer " + auth.token,
27
    },
28
    body: undefined,
29
  });
30
  if (!response.ok) {
31
    const text = await response.text();
32
    throw new Error(`${response.status} ${text}`);
33
  }
34
  return await response.json();
35
}
36