Edits history of script submission #5698 for ' Get account audit logs (cloudflare)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Cloudflare = {
      token: string;
      email: string;
      key: string;
    };
    /**
     * Get account audit logs
     * Gets a list of audit logs for an account. Can be filtered by who made the change, on which zone, and the timeframe of the change.
     */
    export async function main(
      auth: Cloudflare,
      account_identifier: string,
      id: string | undefined,
      _export: string | undefined,
      action_type: string | undefined,
      actor_ip: string | undefined,
      actor_email: string | undefined,
      since: string | undefined,
      before: string | undefined,
      zone_name: string | undefined,
      direction: "desc" | "asc" | undefined,
      per_page: string | undefined,
      page: string | undefined,
      hide_user_logs: string | undefined
    ) {
      const url = new URL(
        `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/audit_logs`
      );
      for (const [k, v] of [
        ["id", id],
        ["export", _export],
        ["action.type", action_type],
        ["actor.ip", actor_ip],
        ["actor.email", actor_email],
        ["since", since],
        ["before", before],
        ["zone.name", zone_name],
        ["direction", direction],
        ["per_page", per_page],
        ["page", page],
        ["hide_user_logs", hide_user_logs],
      ]) {
        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 account audit logs
     * Gets a list of audit logs for an account. Can be filtered by who made the change, on which zone, and the timeframe of the change.
     */
    export async function main(
      auth: Cloudflare,
      account_identifier: string,
      id: string | undefined,
      _export: string | undefined,
      action_type: string | undefined,
      actor_ip: string | undefined,
      actor_email: string | undefined,
      since: string | undefined,
      before: string | undefined,
      zone_name: string | undefined,
      direction: "desc" | "asc" | undefined,
      per_page: string | undefined,
      page: string | undefined,
      hide_user_logs: string | undefined
    ) {
      const url = new URL(
        `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/audit_logs`
      );
      for (const [k, v] of [
        ["id", id],
        ["export", _export],
        ["action.type", action_type],
        ["actor.ip", actor_ip],
        ["actor.email", actor_email],
        ["since", since],
        ["before", before],
        ["zone.name", zone_name],
        ["direction", direction],
        ["per_page", per_page],
        ["page", page],
        ["hide_user_logs", hide_user_logs],
      ]) {
        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