0

Query events associated with your organization

by
Published Oct 17, 2025

|Legacy Role|Equivalent Permission Set Role| |-----|--------| |org.user.audit_logs.read|org.permission.audit_logs.read| --------

Script kustomer Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Kustomer = {
3
  apiKey: string;
4
};
5
/**
6
 * Query events associated with your organization
7
 * |Legacy Role|Equivalent Permission Set Role|
8
|-----|--------|
9
|org.user.audit_logs.read|org.permission.audit_logs.read|
10
--------
11
 */
12
export async function main(
13
  auth: Kustomer,
14
  count: string | undefined,
15
  after: string | undefined,
16
  before: string | undefined,
17
  filter_objectType_:
18
    | "bill_subscription"
19
    | "business_rule"
20
    | "company"
21
    | "conversation"
22
    | "customer"
23
    | "message"
24
    | "search"
25
    | "shortcut"
26
    | "user"
27
    | "work_item"
28
    | "ip_rule"
29
    | "work_session"
30
    | "shopify_rest"
31
    | undefined,
32
  filter_objectId_: string | undefined,
33
  filter_userId_: string | undefined,
34
  filter_include_: string | undefined,
35
  filter_start_: string | undefined,
36
  filter_end_: string | undefined,
37
) {
38
  const url = new URL(`https://api.kustomerapp.com/v1/audit-logs`);
39
  for (const [k, v] of [
40
    ["count", count],
41
    ["after", after],
42
    ["before", before],
43
    ["filter[objectType]", filter_objectType_],
44
    ["filter[objectId]", filter_objectId_],
45
    ["filter[userId]", filter_userId_],
46
    ["filter[include]", filter_include_],
47
    ["filter[start]", filter_start_],
48
    ["filter[end]", filter_end_],
49
  ]) {
50
    if (v !== undefined && v !== "" && k !== undefined) {
51
      url.searchParams.append(k, v);
52
    }
53
  }
54
  const response = await fetch(url, {
55
    method: "GET",
56
    headers: {
57
      Authorization: "Bearer " + auth.apiKey,
58
    },
59
    body: undefined,
60
  });
61
  if (!response.ok) {
62
    const text = await response.text();
63
    throw new Error(`${response.status} ${text}`);
64
  }
65
  return await response.json();
66
}
67