Can be used to fetch basic info about a site
1
//native
2
type Discourse = {
3
apiKey: string;
4
defaultHost: string;
5
apiUsername: string;
6
};
7
/**
8
* Get site basic info
9
* Can be used to fetch basic info about a site
10
*/
11
export async function main(auth: Discourse) {
12
const url = new URL(`https://${auth.defaultHost}/site/basic-info.json`);
13
14
const response = await fetch(url, {
15
method: "GET",
16
headers: {
17
"API-KEY": auth.apiKey,
18
"API-USERNAME": auth.apiUsername,
19
},
20
body: undefined,
21
});
22
if (!response.ok) {
23
const text = await response.text();
24
throw new Error(`${response.status} ${text}`);
25
}
26
return await response.json();
27
28