0

Create multiple invites

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 multiple invites
9
 *
10
 */
11
export async function main(
12
  auth: Discourse,
13
  Api_Key: string,
14
  Api_Username: string,
15
  body: {
16
    email?: string;
17
    skip_email?: false | true;
18
    custom_message?: string;
19
    max_redemptions_allowed?: number;
20
    topic_id?: number;
21
    group_ids?: string;
22
    group_names?: string;
23
    expires_at?: string;
24
  },
25
) {
26
  const url = new URL(`https://${auth.defaultHost}/invites/create-multiple.json`);
27

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