Update a team (Legacy)

**Deprecation Notice:** This endpoint route is deprecated and will be removed from the Teams API. We recommend migrating your existing code to use the new [Update a team](https://docs.github.com/rest/reference/teams#update-a-team) endpoint. To edit a team, the authenticated user must either be an organization owner or a team maintainer. **Note:** With nested teams, the `privacy` for parent teams cannot be `secret`.

Script github Verified

by hugo697 ยท 10/25/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 366 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Update a team (Legacy)
6
 * **Deprecation Notice:** This endpoint route is deprecated and will be removed from the Teams API. We recommend migrating your existing code to use the new [Update a team](https://docs.github.com/rest/reference/teams#update-a-team) endpoint.
7

8
To edit a team, the authenticated user must either be an organization owner or a team maintainer.
9

10
**Note:** With nested teams, the `privacy` for parent teams cannot be `secret`.
11
 */
12
export async function main(
13
  auth: Github,
14
  team_id: string,
15
  body: {
16
    description?: string;
17
    name: string;
18
    parent_team_id?: number;
19
    permission?: "pull" | "push" | "admin";
20
    privacy?: "secret" | "closed";
21
    [k: string]: unknown;
22
  }
23
) {
24
  const url = new URL(`https://api.github.com/teams/${team_id}`);
25

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