0

Update a Team Member

by
Published Apr 8, 2025

Update the membership of a Team Member on the Team specified by `teamId`, such as changing the _role_ of the member, or confirming a request to join the Team for an unconfirmed member. The authenticated user must be an `OWNER` of the Team.

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 a Team Member
7
 * Update the membership of a Team Member on the Team specified by `teamId`, such as changing the _role_ of the member, or confirming a request to join the Team for an unconfirmed member. The authenticated user must be an `OWNER` of the Team.
8
 */
9
export async function main(
10
  auth: Vercel,
11
  uid: string,
12
  teamId: string,
13
  body: {
14
    confirmed?: true;
15
    role?: string;
16
    projects?: {
17
      projectId: string;
18
      role: "ADMIN" | "PROJECT_VIEWER" | "PROJECT_DEVELOPER";
19
    }[];
20
    joinedFrom?: { ssoUserId?: null };
21
  },
22
) {
23
  const url = new URL(
24
    `https://api.vercel.com/v1/teams/${teamId}/members/${uid}`,
25
  );
26

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