0

Get Topic for a Kafka Cluster

by
Published Dec 20, 2024

To retrieve a given topic by name from the set of a Kafka cluster's topics, send a GET request to `/v2/databases/$DATABASE_ID/topics/$TOPIC_NAME`. The result will be a JSON object with a `topic` key.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Get Topic for a Kafka Cluster
7
 * To retrieve a given topic by name from the set of a Kafka cluster's topics,
8
send a GET request to `/v2/databases/$DATABASE_ID/topics/$TOPIC_NAME`.
9

10
The result will be a JSON object with a `topic` key.
11

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

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