Get list of available organizations
One script reply has been approved by the moderators Verified

Returns a list with a single organization associated with the API key in the request.

Created by hugo697 182 days ago
Submitted by hugo697 Bun
Verified 182 days ago
1
//native
2
type Clickhouse = {
3
  username: string;
4
  password: string;
5
  host: string;
6
};
7
/**
8
 * Get list of available organizations
9
 * Returns a list with a single organization associated with the API key in the request.
10
 */
11
export async function main(auth: Clickhouse) {
12
  const url = new URL(`https://api.clickhouse.cloud/v1/organizations`);
13

14
  const response = await fetch(url, {
15
    method: "GET",
16
    headers: {
17
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
18
    },
19
    body: undefined,
20
  });
21
  if (!response.ok) {
22
    const text = await response.text();
23
    throw new Error(`${response.status} ${text}`);
24
  }
25
  return await response.json();
26
}
27