0

Invite a user

by
Published Apr 8, 2025

Invite a user to join the team specified in the URL. The authenticated user needs to be an `OWNER` in order to successfully invoke this endpoint. The user can be specified with an email or an ID. If both email and ID are provided, ID will take priority.

Script vercel Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Vercel = {
3
  token: string;
4
};
5
/**
6
 * Invite a user
7
 * Invite a user to join the team specified in the URL. The authenticated user needs to be an `OWNER` in order to successfully invoke this endpoint. The user can be specified with an email or an ID. If both email and ID are provided, ID will take priority.
8
 */
9
export async function main(
10
  auth: Vercel,
11
  teamId: string,
12
  body: {
13
    uid?: string;
14
    email?: string;
15
    role?:
16
      | "OWNER"
17
      | "MEMBER"
18
      | "DEVELOPER"
19
      | "SECURITY"
20
      | "BILLING"
21
      | "VIEWER"
22
      | "CONTRIBUTOR";
23
    projects?: {
24
      projectId: string;
25
      role: "ADMIN" | "PROJECT_VIEWER" | "PROJECT_DEVELOPER";
26
    }[];
27
  },
28
) {
29
  const url = new URL(`https://api.vercel.com/v1/teams/${teamId}/members`);
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