List reactions for a team discussion

List the reactions to a [team discussion](https://docs.github.com/rest/reference/teams#discussions). OAuth access tokens require the `read:discussion` [scope](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/). **Note:** You can also specify a team by `org_id` and `team_id` using the route `GET /organizations/:org_id/team/:team_id/discussions/:discussion_number/reactions`.

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
 * List reactions for a team discussion
6
 * List the reactions to a [team discussion](https://docs.github.com/rest/reference/teams#discussions). OAuth access tokens require the `read:discussion` [scope](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/).
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/discussions/:discussion_number/reactions`.
9
 */
10
export async function main(
11
  auth: Github,
12
  org: string,
13
  team_slug: string,
14
  discussion_number: string,
15
  content:
16
    | "+1"
17
    | "-1"
18
    | "laugh"
19
    | "confused"
20
    | "heart"
21
    | "hooray"
22
    | "rocket"
23
    | "eyes"
24
    | undefined,
25
  per_page: string | undefined,
26
  page: string | undefined
27
) {
28
  const url = new URL(
29
    `https://api.github.com/orgs/${org}/teams/${team_slug}/discussions/${discussion_number}/reactions`
30
  );
31
  for (const [k, v] of [
32
    ["content", content],
33
    ["per_page", per_page],
34
    ["page", page],
35
  ]) {
36
    if (v !== undefined && v !== "") {
37
      url.searchParams.append(k, v);
38
    }
39
  }
40
  const response = await fetch(url, {
41
    method: "GET",
42
    headers: {
43
      Authorization: "Bearer " + auth.token,
44
    },
45
    body: undefined,
46
  });
47
  if (!response.ok) {
48
    const text = await response.text();
49
    throw new Error(`${response.status} ${text}`);
50
  }
51
  return await response.json();
52
}
53