Update organization details
One script reply has been approved by the moderators Verified

Updates organization fields. Requires ADMIN auth key role.

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
 * Update organization details
9
 * Updates organization fields. Requires ADMIN auth key role.
10
 */
11
export async function main(
12
  auth: Clickhouse,
13
  organizationId: string,
14
  body: {
15
    name?: string;
16
    privateEndpoints?: {
17
      add?: {
18
        id?: string;
19
        description?: string;
20
        cloudProvider?: "gcp" | "aws" | "azure";
21
        region?:
22
          | "ap-south-1"
23
          | "ap-southeast-1"
24
          | "eu-central-1"
25
          | "eu-west-1"
26
          | "eu-west-2"
27
          | "us-east-1"
28
          | "us-east-2"
29
          | "us-west-2"
30
          | "ap-southeast-2"
31
          | "ap-northeast-1"
32
          | "us-east1"
33
          | "us-central1"
34
          | "europe-west4"
35
          | "asia-southeast1"
36
          | "eastus"
37
          | "eastus2"
38
          | "westus3"
39
          | "germanywestcentral";
40
      }[];
41
      remove?: {
42
        id?: string;
43
        description?: string;
44
        cloudProvider?: "gcp" | "aws" | "azure";
45
        region?:
46
          | "ap-south-1"
47
          | "ap-southeast-1"
48
          | "eu-central-1"
49
          | "eu-west-1"
50
          | "eu-west-2"
51
          | "us-east-1"
52
          | "us-east-2"
53
          | "us-west-2"
54
          | "ap-southeast-2"
55
          | "ap-northeast-1"
56
          | "us-east1"
57
          | "us-central1"
58
          | "europe-west4"
59
          | "asia-southeast1"
60
          | "eastus"
61
          | "eastus2"
62
          | "westus3"
63
          | "germanywestcentral";
64
      }[];
65
    };
66
  }
67
) {
68
  const url = new URL(
69
    `https://api.clickhouse.cloud/v1/organizations/${organizationId}`
70
  );
71

72
  const response = await fetch(url, {
73
    method: "PATCH",
74
    headers: {
75
      "Content-Type": "application/json",
76
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
77
    },
78
    body: JSON.stringify(body),
79
  });
80
  if (!response.ok) {
81
    const text = await response.text();
82
    throw new Error(`${response.status} ${text}`);
83
  }
84
  return await response.json();
85
}
86