Edits history of script submission #14643 for ' List of organization activities (clickhouse)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Clickhouse = {
      username: string;
      password: string;
      host: string;
    };
    /**
     * List of organization activities
     * Returns a list of all organization activities.
     */
    export async function main(
      auth: Clickhouse,
      organizationId: string,
      from_date: string | undefined,
      to_date: string | undefined
    ) {
      const url = new URL(
        `https://api.clickhouse.cloud/v1/organizations/${organizationId}/activities`
      );
      for (const [k, v] of [
        ["from_date", from_date],
        ["to_date", to_date],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 205 days ago