Edits history of script submission #5485 for ' List page test history (cloudflare)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Cloudflare = {
      token: string;
      email: string;
      key: string;
    };
    /**
     * List page test history
     * Test history (list of tests) for a specific webpage.
     */
    export async function main(
      auth: Cloudflare,
      zone_identifier: string,
      url: string,
      page: string | undefined,
      per_page: string | undefined,
      region:
        | "asia-east1"
        | "asia-northeast1"
        | "asia-northeast2"
        | "asia-south1"
        | "asia-southeast1"
        | "australia-southeast1"
        | "europe-north1"
        | "europe-southwest1"
        | "europe-west1"
        | "europe-west2"
        | "europe-west3"
        | "europe-west4"
        | "europe-west8"
        | "europe-west9"
        | "me-west1"
        | "southamerica-east1"
        | "us-central1"
        | "us-east1"
        | "us-east4"
        | "us-south1"
        | "us-west1"
        | undefined
    ) {
      const url_ = new URL(
        `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/speed_api/pages/${url}/tests`
      );
      for (const [k, v] of [
        ["page", page],
        ["per_page", per_page],
        ["region", region],
      ]) {
        if (v !== undefined && v !== "") {
          url_.searchParams.append(k, v);
        }
      }
      const response = await fetch(url_, {
        method: "GET",
        headers: {
          "X-AUTH-EMAIL": auth.email,
          "X-AUTH-KEY": auth.key,
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 383 days ago

  • nativets
    type Cloudflare = {
      token: string;
      email: string;
      key: string;
    };
    /**
     * List page test history
     * Test history (list of tests) for a specific webpage.
     */
    export async function main(
      auth: Cloudflare,
      zone_identifier: string,
      url: string,
      page: string | undefined,
      per_page: string | undefined,
      region:
        | "asia-east1"
        | "asia-northeast1"
        | "asia-northeast2"
        | "asia-south1"
        | "asia-southeast1"
        | "australia-southeast1"
        | "europe-north1"
        | "europe-southwest1"
        | "europe-west1"
        | "europe-west2"
        | "europe-west3"
        | "europe-west4"
        | "europe-west8"
        | "europe-west9"
        | "me-west1"
        | "southamerica-east1"
        | "us-central1"
        | "us-east1"
        | "us-east4"
        | "us-south1"
        | "us-west1"
        | undefined
    ) {
      const url_ = new URL(
        `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/speed_api/pages/${url}/tests`
      );
      for (const [k, v] of [
        ["page", page],
        ["per_page", per_page],
        ["region", region],
      ]) {
        if (v !== undefined && v !== "") {
          url_.searchParams.append(k, v);
        }
      }
      const response = await fetch(url_, {
        method: "GET",
        headers: {
          "X-AUTH-EMAIL": auth.email,
          "X-AUTH-KEY": auth.key,
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 920 days ago