Skip to content

audit-log create-event --file does not parse occurredAt into a Date #254

Open

Description

@spesnova

Summary

workos audit-log create-event <organization-id> --file event.json parses the JSON file and passes the result directly to the Node SDK. An ISO 8601 occurredAt value remains a string, but the SDK expects a Date and calls event.occurredAt.toISOString(). The command fails locally before sending the event.

The non-file CLI path converts --occurred-at to a Date, so the two paths behave differently. This affects CLI v0.22.0; the same file-handling code is also present on main.

Reproduction

Save this as event.json (using any valid action and organization ID for your environment):

{
  "action": "test.audit_log.emitted",
  "occurredAt": "2026-09-28T08:53:08.000Z",
  "actor": { "type": "user", "id": "user_example", "metadata": {} },
  "targets": [{ "type": "test", "id": "test_example" }],
  "context": { "location": "unknown" }
}
workos audit-log create-event <organization-id> --file event.json

From the current code path, occurredAt remains a string and the SDK call to toISOString() fails. In an actual run with an API-format JSON file using occurred_at instead, I observed undefined is not an object (evaluating 'event.occurredAt.toISOString').

Expected behavior

The CLI should parse and validate occurredAt from the JSON file into a Date before calling the SDK, or clearly support and document a raw API JSON format for --file.

Workaround

Use workos api /audit_logs/events --method POST --file api-event.json --yes, where api-event.json uses the raw API field occurred_at with an ISO 8601 string (rather than the SDK field occurredAt).

Relevant CLI code: https://github.com/workos/cli/blob/v0.22.0/src/commands/audit-log.ts

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions