Export Audit Log Events through the WorkOS Dashboard and API.
You may need to export Audit Log Events in large chunks. WorkOS supports exporting events as CSV files through both the Dashboard and API.
Exports are scoped to a single organization within a specified date range. Events from the past three months can be included in the export. You may define additional filters such as actions
, actors
, and targets
.
Exports can be manually created under the Organization page when viewing Audit Log Events by selecting “Export CSV” from the “Actions” dropdown. Set your filters and select “Generate CSV file”.
import { WorkOS } from '@workos-inc/node'; const workos = new WorkOS('sk_example_123456789'); const auditLogExport = await workos.auditLogs.createExport({ organizationId: 'org_01EHWNCE74X7JSDV0X3SZ3KJNY', rangeStart: new Date('2022-08-31T15:51:23.604Z'), rangeEnd: new Date('2022-08-31T15:51:23.604Z'), }); // Use auditLogExport.id for fetching export at a later time
Once the export has been created, fetch the export at a later time to access the url
of the generated CSV file.
The URL will expire after 10 minutes. If the export is needed again at a later time, refetching the export will regenerate the URL.
import { WorkOS } from '@workos-inc/node'; const workos = new WorkOS('sk_example_123456789'); const auditLogExport = await workos.auditLogs.getExport( 'audit_log_export_01GBT9P815WPET6H8K0XHBACGS', ); // auditLogExport.state `pending` or `ready` // auditLogExport.url available once `state` is `ready`
If the state
of the export is still pending
, poll the export until it is ready for download.