Delete a team

To delete a team, the authenticated user must be an organization owner or team maintainer. If you are an organization owner, deleting a parent team will delete all of its child teams as well. **Note:** You can also specify a team by `org_id` and `team_id` using the route `DELETE /organizations/{org_id}/team/{team_id}`.

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
 * Delete a team
6
 * To delete a team, the authenticated user must be an organization owner or team maintainer.
7

8
If you are an organization owner, deleting a parent team will delete all of its child teams as well.
9

10
**Note:** You can also specify a team by `org_id` and `team_id` using the route `DELETE /organizations/{org_id}/team/{team_id}`.
11
 */
12
export async function main(auth: Github, org: string, team_slug: string) {
13
  const url = new URL(`https://api.github.com/orgs/${org}/teams/${team_slug}`);
14

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