0

List Activities

Published Oct 12, 2026

List audit log events (admin console, logins, Drive, OAuth tokens, …) from the Admin SDK Reports API.

Script gworkspace Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 41 days ago
1
//native
2

3
/**
4
 * List Activities
5
 * List audit log events for one application: admin (Admin console changes), login, drive (file access and sharing), token (third-party app grants), groups, saml, … newest first. Narrow with `user_key` (an email, or `all`), `event_name` (e.g. login_failure, change_user_access), an RFC 3339 time range and `filters` (e.g. `doc_id==abc,visibility==people_with_link`). Returns `items` and `nextPageToken`. Requires admin.reports.audit.readonly on the connection and a Workspace admin with the Reports privilege.
6
 */
7
export async function main(
8
  auth: RT.Gworkspace,
9
  application_name:
10
    | "access_transparency"
11
    | "admin"
12
    | "calendar"
13
    | "chat"
14
    | "drive"
15
    | "gcp"
16
    | "gmail"
17
    | "gplus"
18
    | "groups"
19
    | "groups_enterprise"
20
    | "jamboard"
21
    | "login"
22
    | "meet"
23
    | "mobile"
24
    | "rules"
25
    | "saml"
26
    | "token"
27
    | "user_accounts"
28
    | "context_aware_access"
29
    | "chrome"
30
    | "data_studio"
31
    | "keep"
32
    | "vault"
33
    | "gemini_in_workspace_apps"
34
    | "classroom"
35
    | "assignments"
36
    | "cloud_search"
37
    | "tasks"
38
    | "data_migration"
39
    | "meet_hardware"
40
    | "directory_sync"
41
    | "ldap"
42
    | "profile"
43
    | "access_evaluation"
44
    | "admin_data_action"
45
    | "contacts"
46
    | "takeout"
47
    | "graduation"
48
    | "voice"
49
    | "chrome_sync"
50
    | "workspace_studio"
51
    | "gemini_notebook",
52
  user_key: string = "all",
53
  event_name: string | undefined,
54
  start_time: string | undefined,
55
  end_time: string | undefined,
56
  filters: string | undefined,
57
  actor_ip_address: string | undefined,
58
  org_unit_id: string | undefined,
59
  max_results: number = 100,
60
  page_token: string | undefined
61
) {
62
  const url = new URL(
63
    `https://admin.googleapis.com/admin/reports/v1/activity/users/${encodeURIComponent(user_key || "all")}/applications/${application_name}`
64
  )
65
  for (const [k, v] of Object.entries({
66
    eventName: event_name,
67
    startTime: start_time,
68
    endTime: end_time,
69
    filters,
70
    actorIpAddress: actor_ip_address,
71
    orgUnitID: org_unit_id,
72
    pageToken: page_token,
73
  })) {
74
    if (v != null && v !== "") url.searchParams.append(k, v)
75
  }
76
  url.searchParams.append("maxResults", String(max_results))
77

78
  const response = await fetch(url, {
79
    headers: {
80
      Authorization: `Bearer ${auth.token}`,
81
      Accept: "application/json",
82
    },
83
  })
84

85
  if (!response.ok) {
86
    throw new Error(`${response.status} ${await response.text()}`)
87
  }
88

89
  return await response.json()
90
}
91