Core
IoT Platform v2.x
2

postTrail #

Manually writes an audit trail entry into the given tenant index.

This is intended for integrators who need to record an action that is not covered by an event-based hook (e.g. an action triggered by an external system). For event-driven recording, prefer registerAuditHook.

The status field must be one of the keys currently registered in the audit trail registry. Use getStatuses to retrieve the valid values.


Query Syntax #

HTTP #

URL: http://kuzzle:7512/_/auditTrail/:index/trail/
Method: POST
Body:
{
  "action": {
    "name": "string"
  },
  "createdAt": "string",
  "status": "string",
  "userId": "string",
  "object": {
    "id": "string",
    "type": "string"
  },
  "customData": {}
}

Javascript #

kuzzle.query({
  controller: 'audit-trail',
  action: 'postTrail',
  index: '<tenant-index>',
  body: {
    action: { name: 'createThing' },
    createdAt: new Date().toISOString(),
    status: 'thingCreated',
    userId: '<kuid>',
    object: {
      id: '<thing-id>',
      type: 'myThing',
    },
    customData: {},
  },
});

Arguments #

ArgumentTypeDescription
index
string
Tenant index name

Body Properties #

PropertyTypeRequiredDescription
action
object
YesAction object. Must have a non-empty name string property
createdAt
string
YesISO 8601 timestamp of when the action occurred
status
string
YesStatus key. Must be one of the keys returned by getStatuses
userId
string
YesKuzzle user identifier (kuid) of the user who performed the action
object
object
NoAudited object. Must have non-empty id and type string properties. Omit if no specific object is associated with the action
customData
object
NoArbitrary additional data to attach to the entry. Defaults to {}

Response #

Returns the created audit trail document.

{
  "_id": "<document-id>",
  "_source": {
    "action": { "name": "createThing" },
    "status": { "name": "thingCreated" },
    "createdAt": "2024-01-15T10:30:00.000Z",
    "user": {
      "kuid": "<kuid>",
      "fullName": "Jane Doe"
    },
    "object": {
      "id": "<thing-id>",
      "type": "myThing"
    },
    "customData": {},
    "schemaVersion": 1
  }
}