Insert into Audit Table via API

2020-08-07

You can insert records into the "Client API Actions" audit log table via the standard LabKey Query APIs, such as LABKEY.Query.insertRows() in the JavaScript client API. For example, you could insert audit records to log when code modifies data in your custom tables, record client-side errors, etc.

Logged-in users can insert into the audit log for any folder to which they have read access. Guests cannot insert to the audit table. Rows can only be inserted, they cannot be deleted or updated. A simple example using the JavaScript API:

LABKEY.Query.insertRows({
schemaName: 'auditLog',
queryName: 'Client API Actions',
rows: [ {
comment: 'Test event insertion via client API',
int1: 5
} ]
});

"Client API Actions" is the only audit log table that allows direct inserts.

For details on the LABKEY.Query API, see the documentation for LABKEY.Query.