Create waiting room

Creates a new waiting room.

Script cloudflare Verified

by hugo697 ยท 11/16/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 383 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Create waiting room
8
 * Creates a new waiting room.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  zone_identifier: string,
13
  body: {
14
    additional_routes?: {
15
      host?: string;
16
      path?: string;
17
      [k: string]: unknown;
18
    }[];
19
    cookie_attributes?: {
20
      samesite?: "auto" | "lax" | "none" | "strict";
21
      secure?: "auto" | "always" | "never";
22
      [k: string]: unknown;
23
    };
24
    cookie_suffix?: string;
25
    custom_page_html?: string;
26
    default_template_language?:
27
      | "en-US"
28
      | "es-ES"
29
      | "de-DE"
30
      | "fr-FR"
31
      | "it-IT"
32
      | "ja-JP"
33
      | "ko-KR"
34
      | "pt-BR"
35
      | "zh-CN"
36
      | "zh-TW"
37
      | "nl-NL"
38
      | "pl-PL"
39
      | "id-ID"
40
      | "tr-TR"
41
      | "ar-EG"
42
      | "ru-RU"
43
      | "fa-IR";
44
    description?: string;
45
    disable_session_renewal?: boolean;
46
    host: string;
47
    json_response_enabled?: boolean;
48
    name: string;
49
    new_users_per_minute: number;
50
    path?: string;
51
    queue_all?: boolean;
52
    queueing_method?: "fifo" | "random" | "passthrough" | "reject";
53
    queueing_status_code?: 200 | 202 | 429;
54
    session_duration?: number;
55
    suspended?: boolean;
56
    total_active_users: number;
57
    [k: string]: unknown;
58
  }
59
) {
60
  const url = new URL(
61
    `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/waiting_rooms`
62
  );
63

64
  const response = await fetch(url, {
65
    method: "POST",
66
    headers: {
67
      "X-AUTH-EMAIL": auth.email,
68
      "X-AUTH-KEY": auth.key,
69
      "Content-Type": "application/json",
70
      Authorization: "Bearer " + auth.token,
71
    },
72
    body: JSON.stringify(body),
73
  });
74
  if (!response.ok) {
75
    const text = await response.text();
76
    throw new Error(`${response.status} ${text}`);
77
  }
78
  return await response.json();
79
}
80