Edits history of script submission #16727 for ' Query events associated with your organization (kustomer)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Kustomer = {
      apiKey: string;
    };
    /**
     * Query events associated with your organization
     * |Legacy Role|Equivalent Permission Set Role|
    |-----|--------|
    |org.user.audit_logs.read|org.permission.audit_logs.read|
    --------
     */
    export async function main(
      auth: Kustomer,
      count: string | undefined,
      after: string | undefined,
      before: string | undefined,
      filter_objectType_:
        | "bill_subscription"
        | "business_rule"
        | "company"
        | "conversation"
        | "customer"
        | "message"
        | "search"
        | "shortcut"
        | "user"
        | "work_item"
        | "ip_rule"
        | "work_session"
        | "shopify_rest"
        | undefined,
      filter_objectId_: string | undefined,
      filter_userId_: string | undefined,
      filter_include_: string | undefined,
      filter_start_: string | undefined,
      filter_end_: string | undefined,
    ) {
      const url = new URL(`https://api.kustomerapp.com/v1/audit-logs`);
      for (const [k, v] of [
        ["count", count],
        ["after", after],
        ["before", before],
        ["filter[objectType]", filter_objectType_],
        ["filter[objectId]", filter_objectId_],
        ["filter[userId]", filter_userId_],
        ["filter[include]", filter_include_],
        ["filter[start]", filter_start_],
        ["filter[end]", filter_end_],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.apiKey,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago