Add an Entry to the Audit Log API
On this page
This API allows you to insert an Audit Log. Generally, Audit Logs are created automatically whenever an admin does something from the FusionAuth UI. However, you can use this API to insert Audit Logs directly if you need.
Request#
Send the message and user responsible for the action in the request body, along with any optional details.
OpenAPI Spec
Request Body#
auditLog.data An object that can hold additional details of an audit log.
auditLog.newValue Intended to be utilized during a change to record the new value.
auditLog.oldValue Intended to be utilized during a change to record the old value prior to the change.
auditLog.reason Intended to be utilized during a change to indicate the reason for the modification.
auditLog.tenantId The Id of the Tenant associated with this Audit Log. This field will be overridden if the request contains an X-FusionAuth-TenantId header, or if the supplied API key is scoped to a specific Tenant.
auditLog.insertUser The user that took the action that is being written to the Audit Logs. We suggest you use email addresses for this field.
auditLog.message The message of the Audit Log.
eventInfoInformation about the request. FusionAuth adds the information to the events the request triggers, as event.info. For more information, see Pass Context From API Requests to Webhooks.
eventInfo.data An object that holds any JSON you choose, such as a trace Id. FusionAuth copies the object to event.info.data without changes.
eventInfo.deviceDescription A description of the end user's device.
eventInfo.deviceName The name of the end user's device.
eventInfo.deviceType The type of the end user's device.
eventInfo.ipAddress The IP address of the end user. When your server calls FusionAuth for the end user, set this value to the end user's IP address. When this value is omitted, FusionAuth uses the IP address of the client that sent the request.
eventInfo.os The operating system of the end user's device.
eventInfo.userAgent The user agent of the end user's browser.
{
"auditLog": {
"data": {
"externalId": "_applicationA"
},
"newValue:": "{\"name\": \"bar\"}",
"oldValue": "{\"name\": \"foo\"}",
"reason": "Because I like to change things.",
"insertUser": "user@fusionauth.io",
"message": "Example audit log"
}
}Response#
The response for this API does not contain a body. It only contains a status code.
| Code | Description |
|---|---|
| 200 | The request succeeded. The response contains a JSON body. |
| 400 | The request was invalid or malformed. The response contains an Errors JSON object with the specific errors. FusionAuth also returns a 400 when the request needs a paid FusionAuth license and no license is present. |
| 401 | FusionAuth didn't authorize the request. The Authorization header is missing, the API key isn't valid, or the API key doesn't have permission for this endpoint and method. The response is empty. For more information, see Unauthorized Responses. |
| 500 | FusionAuth had an internal error and logged a stack trace in the FusionAuth log files. The response usually contains an Errors JSON object with the [Exception] general error code. On MySQL, a data field larger than the database column also returns 500. For more information, see Data Field Sizes. |
| 503 | The search index is unavailable or returned an error, so FusionAuth can't complete the request. The response contains a JSON body. |
Related
Learn about the APIs for adding entries to, searching, and exporting the audit log.
API documentation for the FusionAuth Export Audit Logs API.
API documentation for the FusionAuth Retrieve an Audit Log API.
API documentation for the FusionAuth Search the Audit Log API.