Create a 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
 * Create a 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
  body: { body: string; private?: boolean; title: string; [k: string]: unknown }
12
) {
13
  const url = new URL(`https://api.github.com/teams/${team_id}/discussions`);
14

15
  const response = await fetch(url, {
16
    method: "POST",
17
    headers: {
18
      "Content-Type": "application/json",
19
      Authorization: "Bearer " + auth.token,
20
    },
21
    body: JSON.stringify(body),
22
  });
23
  if (!response.ok) {
24
    const text = await response.text();
25
    throw new Error(`${response.status} ${text}`);
26
  }
27
  return await response.json();
28
}
29