0

Create an access group project

by
Published Apr 8, 2025

Allows creation of an access group project

Script vercel Verified

The script

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