0

Lists all sinks

by
Published Dec 20, 2024

To list all sinks, send a GET request to `/v2/monitoring/sinks`.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Lists all sinks
7
 * To list all sinks, send a GET request to `/v2/monitoring/sinks`.
8
 */
9
export async function main(
10
  auth: Digitalocean,
11
  resource_id: string | undefined,
12
) {
13
  const url = new URL(`https://api.digitalocean.com/v2/monitoring/sinks`);
14
  for (const [k, v] of [["resource_id", resource_id]]) {
15
    if (v !== undefined && v !== "" && k !== undefined) {
16
      url.searchParams.append(k, v);
17
    }
18
  }
19
  const response = await fetch(url, {
20
    method: "GET",
21
    headers: {
22
      Authorization: "Bearer " + auth.token,
23
    },
24
    body: undefined,
25
  });
26
  if (!response.ok) {
27
    const text = await response.text();
28
    throw new Error(`${response.status} ${text}`);
29
  }
30
  return await response.json();
31
}
32