0

Update an access group

by
Published Apr 8, 2025

Allows to update an access group metadata

Script vercel Verified

The script

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