0

Update the status of a topic

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
 * Update the status of a topic
9
 *
10
 */
11
export async function main(
12
  auth: Discourse,
13
  id: string,
14
  Api_Key: string,
15
  Api_Username: string,
16
  body: {
17
    status: "closed" | "pinned" | "pinned_globally" | "archived" | "visible";
18
    enabled: "true" | "false";
19
    until?: string;
20
  },
21
) {
22
  const url = new URL(`https://${auth.defaultHost}/t/${id}/status.json`);
23

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