Update event

Updates a configured event for a 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
 * Update event
8
 * Updates a configured event for a waiting room.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  event_id: string,
13
  waiting_room_id: string,
14
  zone_identifier: string,
15
  body: {
16
    custom_page_html?: string;
17
    description?: string;
18
    disable_session_renewal?: boolean;
19
    event_end_time: string;
20
    event_start_time: string;
21
    name: string;
22
    new_users_per_minute?: number;
23
    prequeue_start_time?: string;
24
    queueing_method?: string;
25
    session_duration?: number;
26
    shuffle_at_event_start?: boolean;
27
    suspended?: boolean;
28
    total_active_users?: number;
29
    [k: string]: unknown;
30
  }
31
) {
32
  const url = new URL(
33
    `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/waiting_rooms/${waiting_room_id}/events/${event_id}`
34
  );
35

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