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