Get a team by name

Gets a team using the team's `slug`. To create the `slug`, GitHub replaces special characters in the `name` string, changes all words to lowercase, and replaces spaces with a `-` separator. For example, `"My TEam Näme"` would become `my-team-name`. **Note:** You can also specify a team by `org_id` and `team_id` using the route `GET /organizations/{org_id}/team/{team_id}`.

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 a team by name
6
 * Gets a team using the team's `slug`. To create the `slug`, GitHub replaces special characters in the `name` string, changes all words to lowercase, and replaces spaces with a `-` separator. For example, `"My TEam Näme"` would become `my-team-name`.
7

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

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