Edits history of script submission #5378 for ' Get logs RayIDs (cloudflare)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Cloudflare = {
      token: string;
      email: string;
      key: string;
    };
    /**
     * Get logs RayIDs
     * The `/rayids` api route allows lookups by specific rayid. The rayids route will return zero, one, or more records (ray ids are not unique).
     */
    export async function main(
      auth: Cloudflare,
      ray_identifier: string,
      zone_identifier: string,
      timestamps: "unix" | "unixnano" | "rfc3339" | undefined,
      fields: string | undefined
    ) {
      const url = new URL(
        `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/logs/rayids/${ray_identifier}`
      );
      for (const [k, v] of [
        ["timestamps", timestamps],
        ["fields", fields],
      ]) {
        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;
    };
    /**
     * Get logs RayIDs
     * The `/rayids` api route allows lookups by specific rayid. The rayids route will return zero, one, or more records (ray ids are not unique).
     */
    export async function main(
      auth: Cloudflare,
      ray_identifier: string,
      zone_identifier: string,
      timestamps: "unix" | "unixnano" | "rfc3339" | undefined,
      fields: string | undefined
    ) {
      const url = new URL(
        `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/logs/rayids/${ray_identifier}`
      );
      for (const [k, v] of [
        ["timestamps", timestamps],
        ["fields", fields],
      ]) {
        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