List of organization activities
One script reply has been approved by the moderators Verified

Returns a list of all organization activities.

Created by hugo697 141 days ago
Submitted by hugo697 Bun
Verified 141 days ago
1
//native
2
type Clickhouse = {
3
  username: string;
4
  password: string;
5
  host: string;
6
};
7
/**
8
 * List of organization activities
9
 * Returns a list of all organization activities.
10
 */
11
export async function main(
12
  auth: Clickhouse,
13
  organizationId: string,
14
  from_date: string | undefined,
15
  to_date: string | undefined
16
) {
17
  const url = new URL(
18
    `https://api.clickhouse.cloud/v1/organizations/${organizationId}/activities`
19
  );
20
  for (const [k, v] of [
21
    ["from_date", from_date],
22
    ["to_date", to_date],
23
  ]) {
24
    if (v !== undefined && v !== "" && k !== undefined) {
25
      url.searchParams.append(k, v);
26
    }
27
  }
28
  const response = await fetch(url, {
29
    method: "GET",
30
    headers: {
31
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
32
    },
33
    body: undefined,
34
  });
35
  if (!response.ok) {
36
    const text = await response.text();
37
    throw new Error(`${response.status} ${text}`);
38
  }
39
  return await response.json();
40
}
41