Create an invitation
One script reply has been approved by the moderators Verified

Creates organization invitation.

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

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