1
//native
2
type Discourse = {
3
apiKey: string;
4
defaultHost: string;
5
apiUsername: string;
6
};
7
/**
8
* Creates a tag group
9
*
10
*/
11
export async function main(auth: Discourse, body: { name: string }) {
12
const url = new URL(`https://${auth.defaultHost}/tag_groups.json`);
13
14
const response = await fetch(url, {
15
method: "POST",
16
headers: {
17
"Content-Type": "application/json",
18
"API-KEY": auth.apiKey,
19
"API-USERNAME": auth.apiUsername,
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