List reactions for a team discussion (Legacy)

**Deprecation Notice:** This endpoint route is deprecated and will be removed from the Teams API.

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 (Legacy)
6
 * **Deprecation Notice:** This endpoint route is deprecated and will be removed from the Teams API.
7
 */
8
export async function main(
9
  auth: Github,
10
  team_id: string,
11
  discussion_number: string,
12
  content:
13
    | "+1"
14
    | "-1"
15
    | "laugh"
16
    | "confused"
17
    | "heart"
18
    | "hooray"
19
    | "rocket"
20
    | "eyes"
21
    | undefined,
22
  per_page: string | undefined,
23
  page: string | undefined
24
) {
25
  const url = new URL(
26
    `https://api.github.com/teams/${team_id}/discussions/${discussion_number}/reactions`
27
  );
28
  for (const [k, v] of [
29
    ["content", content],
30
    ["per_page", per_page],
31
    ["page", page],
32
  ]) {
33
    if (v !== undefined && v !== "") {
34
      url.searchParams.append(k, v);
35
    }
36
  }
37
  const response = await fetch(url, {
38
    method: "GET",
39
    headers: {
40
      Authorization: "Bearer " + auth.token,
41
    },
42
    body: undefined,
43
  });
44
  if (!response.ok) {
45
    const text = await response.text();
46
    throw new Error(`${response.status} ${text}`);
47
  }
48
  return await response.json();
49
}
50