Edits history of script submission #14656 for ' Update service state (clickhouse)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Clickhouse = {
      username: string;
      password: string;
      host: string;
    };
    /**
     * Update service state
     * Starts or stop service
     */
    export async function main(
      auth: Clickhouse,
      organizationId: string,
      serviceId: string,
      body: { command?: "start" | "stop" }
    ) {
      const url = new URL(
        `https://api.clickhouse.cloud/v1/organizations/${organizationId}/services/${serviceId}/state`
      );
    
      const response = await fetch(url, {
        method: "PATCH",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago