Get team member (Legacy)

The "Get team member" endpoint (described below) is deprecated. We recommend using the [Get team membership for a user](https://docs.github.com/rest/reference/teams#get-team-membership-for-a-user) endpoint instead. It allows you to get both active and pending memberships. To list members in a team, the team must be visible to the authenticated user.

Script github Verified

by hugo697 ยท 10/25/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 367 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Get team member (Legacy)
6
 * The "Get team member" endpoint (described below) is deprecated.
7

8
We recommend using the [Get team membership for a user](https://docs.github.com/rest/reference/teams#get-team-membership-for-a-user) endpoint instead. It allows you to get both active and pending memberships.
9

10
To list members in a team, the team must be visible to the authenticated user.
11
 */
12
export async function main(auth: Github, team_id: string, username: string) {
13
  const url = new URL(
14
    `https://api.github.com/teams/${team_id}/members/${username}`
15
  );
16

17
  const response = await fetch(url, {
18
    method: "GET",
19
    headers: {
20
      Authorization: "Bearer " + auth.token,
21
    },
22
    body: undefined,
23
  });
24
  if (!response.ok) {
25
    const text = await response.text();
26
    throw new Error(`${response.status} ${text}`);
27
  }
28
  return await response.text();
29
}
30