0

Get the notifications that belong to the current user

by
Published Oct 17, 2025
Script discourse Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Discourse = {
3
  apiKey: string;
4
  defaultHost: string;
5
  apiUsername: string;
6
};
7
/**
8
 * Get the notifications that belong to the current user
9
 *
10
 */
11
export async function main(auth: Discourse) {
12
  const url = new URL(`https://${auth.defaultHost}/notifications.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