0

Invite users in an organization

by
Published Oct 17, 2025
Script gitbook Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Gitbook = {
3
  token: string;
4
};
5
/**
6
 * Invite users in an organization
7
 *
8
 */
9
export async function main(
10
  auth: Gitbook,
11
  organizationId: string,
12
  body: {
13
    emails:
14
      | string
15
      | {
16
          email: string;
17
          role: "admin" | "create" | "edit" | "review" | "comment" | "read";
18
        }[];
19
    role?: "admin" | "create" | "edit" | "review" | "comment" | "read";
20
    sso?: false | true;
21
  },
22
) {
23
  const url = new URL(`https://api.gitbook.com/v1/orgs/${organizationId}/invites`);
24

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