0

Updates a category

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
 * Updates a category
9
 *
10
 */
11
export async function main(
12
  auth: Discourse,
13
  id: string,
14
  body: {
15
    name: string;
16
    color?: string;
17
    text_color?: string;
18
    parent_category_id?: number;
19
    allow_badges?: false | true;
20
    slug?: string;
21
    topic_featured_links_allowed?: false | true;
22
    permissions?: { everyone?: number; staff?: number };
23
    search_priority?: number;
24
    form_template_ids?: unknown[];
25
  },
26
) {
27
  const url = new URL(`https://${auth.defaultHost}/categories/${id}.json`);
28

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