Edits history of script submission #14650 for ' Update organization details (clickhouse)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Clickhouse = {
      username: string;
      password: string;
      host: string;
    };
    /**
     * Update organization details
     * Updates organization fields. Requires ADMIN auth key role.
     */
    export async function main(
      auth: Clickhouse,
      organizationId: string,
      body: {
        name?: string;
        privateEndpoints?: {
          add?: {
            id?: string;
            description?: string;
            cloudProvider?: "gcp" | "aws" | "azure";
            region?:
              | "ap-south-1"
              | "ap-southeast-1"
              | "eu-central-1"
              | "eu-west-1"
              | "eu-west-2"
              | "us-east-1"
              | "us-east-2"
              | "us-west-2"
              | "ap-southeast-2"
              | "ap-northeast-1"
              | "us-east1"
              | "us-central1"
              | "europe-west4"
              | "asia-southeast1"
              | "eastus"
              | "eastus2"
              | "westus3"
              | "germanywestcentral";
          }[];
          remove?: {
            id?: string;
            description?: string;
            cloudProvider?: "gcp" | "aws" | "azure";
            region?:
              | "ap-south-1"
              | "ap-southeast-1"
              | "eu-central-1"
              | "eu-west-1"
              | "eu-west-2"
              | "us-east-1"
              | "us-east-2"
              | "us-west-2"
              | "ap-southeast-2"
              | "ap-northeast-1"
              | "us-east1"
              | "us-central1"
              | "europe-west4"
              | "asia-southeast1"
              | "eastus"
              | "eastus2"
              | "westus3"
              | "germanywestcentral";
          }[];
        };
      }
    ) {
      const url = new URL(
        `https://api.clickhouse.cloud/v1/organizations/${organizationId}`
      );
    
      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