Create reaction 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 367 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Create reaction 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
  body: {
13
    content:
14
      | "+1"
15
      | "-1"
16
      | "laugh"
17
      | "confused"
18
      | "heart"
19
      | "hooray"
20
      | "rocket"
21
      | "eyes";
22
    [k: string]: unknown;
23
  }
24
) {
25
  const url = new URL(
26
    `https://api.github.com/teams/${team_id}/discussions/${discussion_number}/reactions`
27
  );
28

29
  const response = await fetch(url, {
30
    method: "POST",
31
    headers: {
32
      "Content-Type": "application/json",
33
      Authorization: "Bearer " + auth.token,
34
    },
35
    body: JSON.stringify(body),
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.json();
42
}
43