0

List organization invitation teams

by
Published Oct 25, 2023

List all teams associated with an invitation. In order to see invitations in an organization, the authenticated user must be an organization owner.

Script github Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 398 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * List organization invitation teams
6
 * List all teams associated with an invitation. In order to see invitations in an organization, the authenticated user must be an organization owner.
7
 */
8
export async function main(
9
  auth: Github,
10
  org: string,
11
  invitation_id: string,
12
  per_page: string | undefined,
13
  page: string | undefined
14
) {
15
  const url = new URL(
16
    `https://api.github.com/orgs/${org}/invitations/${invitation_id}/teams`
17
  );
18
  for (const [k, v] of [
19
    ["per_page", per_page],
20
    ["page", page],
21
  ]) {
22
    if (v !== undefined && v !== "") {
23
      url.searchParams.append(k, v);
24
    }
25
  }
26
  const response = await fetch(url, {
27
    method: "GET",
28
    headers: {
29
      Authorization: "Bearer " + auth.token,
30
    },
31
    body: undefined,
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39