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

Updates organization member role.

Created by hugo697 141 days ago Picked 2 times
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 member.
9
 * Updates organization member role.
10
 */
11
export async function main(
12
  auth: Clickhouse,
13
  organizationId: string,
14
  userId: string,
15
  body: { role?: "admin" | "developer" | "org_member" | "billing" }
16
) {
17
  const url = new URL(
18
    `https://api.clickhouse.cloud/v1/organizations/${organizationId}/members/${userId}`
19
  );
20

21
  const response = await fetch(url, {
22
    method: "PATCH",
23
    headers: {
24
      "Content-Type": "application/json",
25
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
26
    },
27
    body: JSON.stringify(body),
28
  });
29
  if (!response.ok) {
30
    const text = await response.text();
31
    throw new Error(`${response.status} ${text}`);
32
  }
33
  return await response.json();
34
}
35