0

Creates an access group

by
Published Apr 8, 2025

Allows to create an access group

Script vercel Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Vercel = {
3
  token: string;
4
};
5
/**
6
 * Creates an access group
7
 * Allows to create an access group
8
 */
9
export async function main(
10
  auth: Vercel,
11
  teamId: string | undefined,
12
  slug: string | undefined,
13
  body: {
14
    name: string;
15
    projects?: {
16
      projectId: string;
17
      role: "ADMIN" | "PROJECT_VIEWER" | "PROJECT_DEVELOPER";
18
    }[];
19
    membersToAdd?: string[];
20
  },
21
) {
22
  const url = new URL(`https://api.vercel.com/v1/access-groups`);
23
  for (const [k, v] of [
24
    ["teamId", teamId],
25
    ["slug", slug],
26
  ]) {
27
    if (v !== undefined && v !== "" && k !== undefined) {
28
      url.searchParams.append(k, v);
29
    }
30
  }
31
  const response = await fetch(url, {
32
    method: "POST",
33
    headers: {
34
      "Content-Type": "application/json",
35
      Authorization: "Bearer " + auth.token,
36
    },
37
    body: JSON.stringify(body),
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45