0

Create topic timer

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
 * Create topic timer
9
 *
10
 */
11
export async function main(
12
  auth: Discourse,
13
  id: string,
14
  Api_Key: string,
15
  Api_Username: string,
16
  body: {
17
    time?: string;
18
    status_type?: string;
19
    based_on_last_post?: false | true;
20
    category_id?: number;
21
  },
22
) {
23
  const url = new URL(`https://${auth.defaultHost}/t/${id}/timer.json`);
24

25
  const response = await fetch(url, {
26
    method: "POST",
27
    headers: {
28
      "Content-Type": "application/json",
29
      "API-KEY": auth.apiKey,
30
      "API-USERNAME": auth.apiUsername,
31
    },
32
    body: JSON.stringify(body),
33
  });
34
  if (!response.ok) {
35
    const text = await response.text();
36
    throw new Error(`${response.status} ${text}`);
37
  }
38
  return await response.json();
39
}
40