0

Get a Zone Lockdown rule

by
Published Nov 16, 2023

Fetches the details of a Zone Lockdown rule.

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
     * Get a Zone Lockdown rule
    8
     * Fetches the details of a Zone Lockdown rule.
    9
     */
    10
    export async function main(
    11
      auth: Cloudflare,
    12
      id: string,
    13
      zone_identifier: string
    14
    ) {
    15
      const url = new URL(
    16
        `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/firewall/lockdowns/${id}`
    17
      );
    18
    
    
    19
      const response = await fetch(url, {
    20
        method: "GET",
    21
        headers: {
    22
          "X-AUTH-EMAIL": auth.email,
    23
          "X-AUTH-KEY": auth.key,
    24
          Authorization: "Bearer " + auth.token,
    25
        },
    26
        body: undefined,
    27
      });
    28
      if (!response.ok) {
    29
        const text = await response.text();
    30
        throw new Error(`${response.status} ${text}`);
    31
      }
    32
      return await response.json();
    33
    }
    34