Create event

Only available for the Waiting Room Advanced subscription. Creates an event for a waiting room. An event takes place during a specified period of time, temporarily changing the behavior of a waiting room. While the event is active, some of the properties in the event's configuration may either override or inherit from the waiting room's configuration. Note that events cannot overlap with each other, so only one event can be active at a time.

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 event
8
 * Only available for the Waiting Room Advanced subscription. Creates an event for a waiting room. An event takes place during a specified period of time, temporarily changing the behavior of a waiting room. While the event is active, some of the properties in the event's configuration may either override or inherit from the waiting room's configuration. Note that events cannot overlap with each other, so only one event can be active at a time.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  waiting_room_id: string,
13
  zone_identifier: string,
14
  body: {
15
    custom_page_html?: string;
16
    description?: string;
17
    disable_session_renewal?: boolean;
18
    event_end_time: string;
19
    event_start_time: string;
20
    name: string;
21
    new_users_per_minute?: number;
22
    prequeue_start_time?: string;
23
    queueing_method?: string;
24
    session_duration?: number;
25
    shuffle_at_event_start?: boolean;
26
    suspended?: boolean;
27
    total_active_users?: number;
28
    [k: string]: unknown;
29
  }
30
) {
31
  const url = new URL(
32
    `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/waiting_rooms/${waiting_room_id}/events`
33
  );
34

35
  const response = await fetch(url, {
36
    method: "POST",
37
    headers: {
38
      "X-AUTH-EMAIL": auth.email,
39
      "X-AUTH-KEY": auth.key,
40
      "Content-Type": "application/json",
41
      Authorization: "Bearer " + auth.token,
42
    },
43
    body: JSON.stringify(body),
44
  });
45
  if (!response.ok) {
46
    const text = await response.text();
47
    throw new Error(`${response.status} ${text}`);
48
  }
49
  return await response.json();
50
}
51