Query and export the audit log
Find who did what, and export a period as CSV or JSON for a review.
What it shows
- Filter the audit log by action, by result and by time: the failed sign-ins of the last day.
- Read one entry in full, with the reason of the failure.
- List every event about one person, page by page.
- Export the period as a CSV file.
The same four steps run with the lumo CLI and with curl.
Before you start
- An API key with the scope
admin:audit:read. Create it in the portal under Applications & developer tools, API keys. The person who creates the key must hold the permissionsaudit.viewandaudit.export. - Check that your plan includes the export of audit logs in the plans matrix.
- A failed sign-in to look for:
- Run the setup script. It creates the user
audit-user@example.comand prints the address of your sign-in page. - Open that address in a browser.
- Enter
audit-user@example.comand select Continue. - Enter any wrong password and select Sign in. The page answers "Invalid credentials."
- Run the setup script. It creates the user
| Variable | Value |
|---|---|
LUMOAUTH_URL | The address of LumoAuth: https://app.lumoauth.dev, or https://eu.app.lumoauth.dev for the EU region. |
LUMOAUTH_ORG_ID | Your organization, for example acme-corp. |
LUMOAUTH_API_KEY | An API key with the scope admin:audit:read. The setup script also needs admin:users:write. |
AUDIT_USER_ID | The ID of the person whose events you want to read. The setup script prints the ID of its test user. |
SINCE | Optional. The start of the period, as ISO 8601, for example 2026-11-01T00:00:00Z. Default: 24 hours ago. |
EXPORT_FILE | Optional. The file that receives the export. Default: audit-log.csv. |
The setup script creates a test user through the Admin API and prints the address of your sign-in page. You can run it again at any time.
node operations/audit-log-export/setup.mjs
setup.mjs
// Creates the test user of the recipe. Run it again at any time.
//
// node operations/audit-log-export/setup.mjs
//
// The API key needs the scope admin:users:write.
import { randomBytes } from 'node:crypto';
import { ensure, org, printEnv, url } from '../../_lib/admin.mjs';
const user = await ensure('/admin/users', (u) => u.email === 'audit-user@example.com', {
email: 'audit-user@example.com',
name: 'Maya Chen',
// Nobody signs in as this user: the recipe needs a failed sign-in only.
password: `${randomBytes(18).toString('base64url')}#Aa1`,
emailVerified: true,
});
console.log(`The user ${user.email} is ready.`);
console.log(`Now make one failed sign-in: open ${url}/orgs/${org}/login,`);
console.log(`enter ${user.email} and any wrong password.`);
printEnv({ AUDIT_USER_ID: user.id });
Code
Run each command from the recipes folder of the examples repository. Set the folder up once for your language. Every version below was run against a LumoAuth organization.
- lumo CLI
- curl
operations/audit-log-export/cli/audit.sh
#!/bin/sh
# Query the audit log with the lumo CLI: the failed sign-ins of a period,
# every event about one person, and an export of the period as CSV.
#
# sh operations/audit-log-export/cli/audit.sh
#
# The script needs the lumo CLI and jq.
set -eu
# The CLI has its own names for the three values of the recipes.
export LUMO_BASE_URL="$LUMOAUTH_URL" LUMO_ORG="$LUMOAUTH_ORG_ID" LUMO_API_KEY="$LUMOAUTH_API_KEY"
# The start of the period. Default: 24 hours ago (GNU date, then BSD date).
SINCE="${SINCE:-$(date -u -d '1 day ago' +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -v-1d +%Y-%m-%dT%H:%M:%SZ)}"
EXPORT_FILE="${EXPORT_FILE:-audit-log.csv}"
# 1. Filter by action, by result and by time. A failed sign-in has the action
# "login" and the status "failure".
FAILED=$(lumo logs list --action login --status failure --from "$SINCE" --limit 100 -o json)
echo "failed sign-ins since $SINCE: $(printf '%s\n' "$FAILED" | jq '.meta.total')"
# 2. The list leaves the details out. Read one entry for the reason.
for ID in $(printf '%s\n' "$FAILED" | jq -r '.data[:5][].id'); do
lumo logs get "$ID" -o json | jq -r '.data | "\(.id) \(.createdAt) \(.targetName): \(.context.reason)"'
done
# 3. Every event about one person, page by page. `lumo logs list --user`
# filters by the actor. The person of a failed sign-in is the target of the
# entry, and `lumo api` sends that filter.
PAGE=1
while :; do
ANSWER=$(lumo api GET /admin/audit-logs -Q "targetId=$AUDIT_USER_ID" -Q "page=$PAGE" -Q "limit=${PAGE_SIZE:-100}")
[ "$PAGE" = 1 ] && echo "events about $AUDIT_USER_ID: $(printf '%s\n' "$ANSWER" | jq '.meta.total')"
printf '%s\n' "$ANSWER" | jq -r '.data[] | "\(.id) \(.eventType) \(.status)"'
[ "$(printf '%s\n' "$ANSWER" | jq '.meta.hasNextPage')" = "true" ] || break
PAGE=$((PAGE + 1))
done
# 4. Export the period. The answer is the file itself.
lumo logs export --export-format csv --from "$SINCE" > "$EXPORT_FILE"
echo "exported: $EXPORT_FILE, $(($(wc -l < "$EXPORT_FILE") - 1)) rows"
sh operations/audit-log-export/cli/audit.sh
operations/audit-log-export/http/audit.sh
#!/bin/sh
# Query the audit log with curl: the failed sign-ins of a period, every event
# about one person, and an export of the period as CSV.
#
# sh operations/audit-log-export/http/audit.sh
#
# The script needs curl and jq.
set -eu
API="$LUMOAUTH_URL/orgs/$LUMOAUTH_ORG_ID/api/v1/admin/audit-logs"
get() { curl --silent --show-error --fail --get --header "X-API-Key: $LUMOAUTH_API_KEY" "$@"; }
# The start of the period. Default: 24 hours ago (GNU date, then BSD date).
SINCE="${SINCE:-$(date -u -d '1 day ago' +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -v-1d +%Y-%m-%dT%H:%M:%SZ)}"
EXPORT_FILE="${EXPORT_FILE:-audit-log.csv}"
# 1. Filter by action, by result and by time. A failed sign-in has the action
# "login" and the status "failure".
FAILED=$(get "$API" --data-urlencode "action=login" --data-urlencode "status=failure" \
--data-urlencode "from=$SINCE" --data-urlencode "limit=100")
echo "failed sign-ins since $SINCE: $(printf '%s\n' "$FAILED" | jq '.meta.total')"
# 2. The list leaves the details out. Read one entry for the reason.
for ID in $(printf '%s\n' "$FAILED" | jq -r '.data[:5][].id'); do
get "$API/$ID" | jq -r '.data | "\(.id) \(.createdAt) \(.targetName): \(.context.reason)"'
done
# 3. Every event about one person, page by page. The person of a failed
# sign-in is the target of the entry, not the actor.
PAGE=1
while :; do
ANSWER=$(get "$API" --data-urlencode "targetId=$AUDIT_USER_ID" --data-urlencode "page=$PAGE" \
--data-urlencode "limit=${PAGE_SIZE:-100}")
[ "$PAGE" = 1 ] && echo "events about $AUDIT_USER_ID: $(printf '%s\n' "$ANSWER" | jq '.meta.total')"
printf '%s\n' "$ANSWER" | jq -r '.data[] | "\(.id) \(.eventType) \(.status)"'
[ "$(printf '%s\n' "$ANSWER" | jq '.meta.hasNextPage')" = "true" ] || break
PAGE=$((PAGE + 1))
done
# 4. Export the period. The answer is the file itself.
get "$API/export" --data-urlencode "format=csv" --data-urlencode "from=$SINCE" --output "$EXPORT_FILE"
echo "exported: $EXPORT_FILE, $(($(wc -l < "$EXPORT_FILE") - 1)) rows"
sh operations/audit-log-export/http/audit.sh
Check the result
Output
failed sign-ins since 2026-11-26T09:00:00Z: 1
48211 2026-11-27T08:41:12+00:00 audit-user@example.com: The presented password is invalid.
events about 019d6190-9bba-7b5f-a0a5-07a6d10184d2: 3
48211 login.failed failure
48212 user.updated success
48190 user.created success
exported: audit-log.csv, 57 rows
- The second line is the failed sign-in, with the reason that LumoAuth recorded.
- The three events about the person are the creation by the setup script, the failed sign-in, and an update that LumoAuth made after the failure.
- The CSV file has one header row and one row for each entry of the period. For the full entries, with the
contextobject, ask forformat=jsonin the curl version, or--export-format jsonin the CLI version. - The portal shows the same entries under Security, Audit logs. The export is itself an entry there:
audit.exported.
Limits
- One export holds at most 10,000 entries. For a longer period, export it in parts.
- The list and the export return only the entries inside the audit period of your plan. Check the period in the plans matrix.
- An entry stores the network of the caller, not the full IP address.
- The CLI has no command that follows the log as it grows. To get each event when it happens, see Receive webhooks and Stream events to your SIEM.
lumo logs list --userfilters by the actor. A failed sign-in has no signed-in actor, so the recipe finds it by its target.