0

Replace Waiting Room Rules

by
Published Nov 16, 2023

Only available for the Waiting Room Advanced subscription. Replaces all rules for a waiting room.

Script cloudflare
  • Submitted by hugo697 Typescript (fetch-only)
    Created 535 days ago
    1
    type Cloudflare = {
    2
      token: string;
    3
      email: string;
    4
      key: string;
    5
    };
    6
    /**
    7
     * Replace Waiting Room Rules
    8
     * Only available for the Waiting Room Advanced subscription. Replaces all rules for a waiting room.
    9
     */
    10
    export async function main(
    11
      auth: Cloudflare,
    12
      waiting_room_id: string,
    13
      zone_identifier: string,
    14
      body: {
    15
        action: "bypass_waiting_room";
    16
        description?: string;
    17
        enabled?: boolean;
    18
        expression: string;
    19
        [k: string]: unknown;
    20
      }[]
    21
    ) {
    22
      const url = new URL(
    23
        `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/waiting_rooms/${waiting_room_id}/rules`
    24
      );
    25
    
    
    26
      const response = await fetch(url, {
    27
        method: "PUT",
    28
        headers: {
    29
          "X-AUTH-EMAIL": auth.email,
    30
          "X-AUTH-KEY": auth.key,
    31
          "Content-Type": "application/json",
    32
          Authorization: "Bearer " + auth.token,
    33
        },
    34
        body: JSON.stringify(body),
    35
      });
    36
      if (!response.ok) {
    37
        const text = await response.text();
    38
        throw new Error(`${response.status} ${text}`);
    39
      }
    40
      return await response.json();
    41
    }
    42