0

Get audit log events

by
Published Oct 31, 2023

Retrieve the audit log events that have been captured in your domain.

Script asana Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 403 days ago
1
type Asana = {
2
  token: string;
3
};
4
/**
5
 * Get audit log events
6
 * Retrieve the audit log events that have been captured in your domain.
7
 */
8
export async function main(
9
  auth: Asana,
10
  workspace_gid: string,
11
  start_at: string | undefined,
12
  end_at: string | undefined,
13
  event_type: string | undefined,
14
  actor_type:
15
    | "user"
16
    | "asana"
17
    | "asana_support"
18
    | "anonymous"
19
    | "external_administrator"
20
    | undefined,
21
  actor_gid: string | undefined,
22
  resource_gid: string | undefined,
23
  limit: string | undefined,
24
  offset: string | undefined
25
) {
26
  const url = new URL(
27
    `https://app.asana.com/api/1.0/workspaces/${workspace_gid}/audit_log_events`
28
  );
29
  for (const [k, v] of [
30
    ["start_at", start_at],
31
    ["end_at", end_at],
32
    ["event_type", event_type],
33
    ["actor_type", actor_type],
34
    ["actor_gid", actor_gid],
35
    ["resource_gid", resource_gid],
36
    ["limit", limit],
37
    ["offset", offset],
38
  ]) {
39
    if (v !== undefined && v !== "") {
40
      url.searchParams.append(k, v);
41
    }
42
  }
43
  const response = await fetch(url, {
44
    method: "GET",
45
    headers: {
46
      Authorization: "Bearer " + auth.token,
47
    },
48
    body: undefined,
49
  });
50
  if (!response.ok) {
51
    const text = await response.text();
52
    throw new Error(`${response.status} ${text}`);
53
  }
54
  return await response.json();
55
}
56