0

Create a group

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 a group
9
 *
10
 */
11
export async function main(
12
  auth: Discourse,
13
  body: {
14
    group: {
15
      name: string;
16
      full_name?: string;
17
      bio_raw?: string;
18
      usernames?: string;
19
      owner_usernames?: string;
20
      automatic_membership_email_domains?: string;
21
      visibility_level?: number;
22
      primary_group?: false | true;
23
      flair_icon?: string;
24
      flair_upload_id?: number;
25
      flair_bg_color?: string;
26
      public_admission?: false | true;
27
      public_exit?: false | true;
28
      default_notification_level?: number;
29
      muted_category_ids?: number[];
30
      regular_category_ids?: number[];
31
      watching_category_ids?: number[];
32
      tracking_category_ids?: number[];
33
      watching_first_post_category_ids?: number[];
34
    };
35
  },
36
) {
37
  const url = new URL(`https://${auth.defaultHost}/admin/groups.json`);
38

39
  const response = await fetch(url, {
40
    method: "POST",
41
    headers: {
42
      "Content-Type": "application/json",
43
      "API-KEY": auth.apiKey,
44
      "API-USERNAME": auth.apiUsername,
45
    },
46
    body: JSON.stringify(body),
47
  });
48
  if (!response.ok) {
49
    const text = await response.text();
50
    throw new Error(`${response.status} ${text}`);
51
  }
52
  return await response.json();
53
}
54