1 | |
2 |
|
3 | |
4 | * Get System Log Events |
5 | * Query the Okta System Log. Bound the window with `since` / `until` (ISO 8601, e.g. 2026-06-01T00:00:00Z), narrow with a `filter` expression or free-text `q`, and order with `sort_order` (ASCENDING is the default). `limit` defaults to 100 (max 1000); page with the `after` cursor from the previous response's Link header. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Okta, |
9 | since: string | undefined, |
10 | until: string | undefined, |
11 | filter: string | undefined, |
12 | q: string | undefined, |
13 | sort_order: "ASCENDING" | "DESCENDING" | undefined, |
14 | limit: number | undefined, |
15 | after: string | undefined |
16 | ) { |
17 | const url = new URL(`${auth.org_url}/api/v1/logs`) |
18 | if (since !== undefined && since !== "") |
19 | url.searchParams.append("since", since) |
20 | if (until !== undefined && until !== "") |
21 | url.searchParams.append("until", until) |
22 | if (filter !== undefined && filter !== "") |
23 | url.searchParams.append("filter", filter) |
24 | if (q !== undefined && q !== "") url.searchParams.append("q", q) |
25 | if (sort_order !== undefined) url.searchParams.append("sortOrder", sort_order) |
26 | if (limit !== undefined) url.searchParams.append("limit", String(limit)) |
27 | if (after !== undefined && after !== "") |
28 | url.searchParams.append("after", after) |
29 |
|
30 | const response = await fetch(url, { |
31 | method: "GET", |
32 | headers: { |
33 | Authorization: `SSWS ${auth.token}`, |
34 | Accept: "application/json", |
35 | }, |
36 | }) |
37 |
|
38 | if (!response.ok) { |
39 | throw new Error(`${response.status} ${await response.text()}`) |
40 | } |
41 |
|
42 | return await response.json() |
43 | } |
44 |
|