Skip to content

Audit Log API

The Audit Log system automatically records every significant action performed within an organization — create, update, delete, and access events across all resource types. Logs are immutable and queryable for compliance, debugging, and analytics.

Authentication

All audit endpoints require a valid PASETO token and membership in the target organization.

Data Model

Each audit log entry contains:

FieldTypeDescription
_idObjectIdUnique log entry ID
orgIdObjectIdOrganization the action belongs to
userIdObjectIdUser who performed the action
userNamestringDisplay name of the acting user
actionstringAction identifier (e.g. booking.created)
resourceTypestringResource type (e.g. booking, invoice, room)
resourceIdObjectIdID of the affected resource
detailsobjectAction-specific metadata / change summary
ipAddressstringClient IP address
userAgentstringClient user-agent string
createdAtDateISO 8601 timestamp

Example Entry

json
{
  "_id": "65a1b2c3d4e5f6a7b8c9d0e1",
  "orgId": "org_abc123",
  "userId": "usr_xyz789",
  "userName": "John Doe",
  "action": "booking.created",
  "resourceType": "booking",
  "resourceId": "bkg_456def",
  "details": {
    "guestName": "Jane Smith",
    "roomNumber": "201",
    "checkIn": "2026-03-01",
    "checkOut": "2026-03-05"
  },
  "ipAddress": "203.0.113.42",
  "userAgent": "Mozilla/5.0 ...",
  "createdAt": "2026-02-20T14:30:00.000Z"
}

Endpoints

GET /api/audit/:orgId/logs

Retrieve paginated audit logs for an organization with flexible filtering.

Path Parameters

ParamTypeDescription
orgIdstringOrganization ID

Query Parameters

ParamTypeDefaultDescription
pagenumber1Page number
limitnumber50Items per page (max 100)
actionstringFilter by action (e.g. booking.created)
userIdstringFilter by acting user ID
resourceTypestringFilter by resource type (e.g. invoice)
startDatestringISO 8601 start date (inclusive)
endDatestringISO 8601 end date (inclusive)

Example Request

GET /api/audit/org_abc123/logs?page=1&limit=20&action=booking.created&startDate=2026-02-01&endDate=2026-02-28

Response 200 OK

json
{
  "success": true,
  "data": [
    {
      "_id": "65a1b2c3d4e5f6a7b8c9d0e1",
      "action": "booking.created",
      "userName": "John Doe",
      "resourceType": "booking",
      "resourceId": "bkg_456def",
      "details": { "guestName": "Jane Smith", "roomNumber": "201" },
      "createdAt": "2026-02-20T14:30:00.000Z"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 142,
    "pages": 8
  }
}

GET /api/audit/:orgId/statistics

Aggregated audit statistics for the organization — action breakdowns, top actors, daily trends.

Path Parameters

ParamTypeDescription
orgIdstringOrganization ID

Response 200 OK

json
{
  "success": true,
  "statistics": {
    "totalLogs": 4832,
    "actionBreakdown": [
      { "action": "booking.created", "count": 1240 },
      { "action": "invoice.created", "count": 892 },
      { "action": "payment.recorded", "count": 756 },
      { "action": "guest.updated", "count": 510 },
      { "action": "room.updated", "count": 234 }
    ],
    "topActors": [
      { "userId": "usr_xyz789", "userName": "John Doe", "count": 1820 },
      { "userId": "usr_abc456", "userName": "Jane Smith", "count": 1340 }
    ],
    "dailyTrend": [
      { "date": "2026-02-18", "count": 64 },
      { "date": "2026-02-19", "count": 78 },
      { "date": "2026-02-20", "count": 52 }
    ]
  }
}

GET /api/audit/:orgId/by-user/:userId

Retrieve all audit logs for a specific user within the organization.

Path Parameters

ParamTypeDescription
orgIdstringOrganization ID
userIdstringTarget user ID

Query Parameters

ParamTypeDefaultDescription
pagenumber1Page number
limitnumber50Items per page

Response 200 OK

json
{
  "success": true,
  "user": {
    "id": "usr_xyz789",
    "name": "John Doe"
  },
  "data": [
    {
      "_id": "65a1b2c3d4e5f6a7b8c9d0e1",
      "action": "booking.created",
      "resourceType": "booking",
      "resourceId": "bkg_456def",
      "details": { "guestName": "Jane Smith" },
      "createdAt": "2026-02-20T14:30:00.000Z"
    }
  ],
  "pagination": { "page": 1, "limit": 50, "total": 1820, "pages": 37 }
}

GET /api/audit/:orgId/by-resource/:resourceType/:resourceId

Retrieve the complete audit trail for a specific resource (e.g., a single booking or invoice).

Path Parameters

ParamTypeDescription
orgIdstringOrganization ID
resourceTypestringResource type (booking, invoice, room, etc.)
resourceIdstringResource document ID

Response 200 OK

json
{
  "success": true,
  "resource": {
    "type": "booking",
    "id": "bkg_456def"
  },
  "data": [
    {
      "_id": "65a1b2c3d4e5f6a7b8c9d0e1",
      "action": "booking.created",
      "userName": "John Doe",
      "details": { "guestName": "Jane Smith", "roomNumber": "201" },
      "createdAt": "2026-02-20T14:30:00.000Z"
    },
    {
      "_id": "65a1b2c3d4e5f6a7b8c9d0e2",
      "action": "booking.updated",
      "userName": "John Doe",
      "details": { "field": "checkOut", "from": "2026-03-05", "to": "2026-03-07" },
      "createdAt": "2026-02-21T09:15:00.000Z"
    }
  ]
}

GET /api/audit/:orgId/:logId

Fetch a single audit log entry by its ID.

Path Parameters

ParamTypeDescription
orgIdstringOrganization ID
logIdstringAudit log ID

Response 200 OK

json
{
  "success": true,
  "log": {
    "_id": "65a1b2c3d4e5f6a7b8c9d0e1",
    "orgId": "org_abc123",
    "userId": "usr_xyz789",
    "userName": "John Doe",
    "action": "booking.created",
    "resourceType": "booking",
    "resourceId": "bkg_456def",
    "details": {
      "guestName": "Jane Smith",
      "roomNumber": "201",
      "checkIn": "2026-03-01",
      "checkOut": "2026-03-05"
    },
    "ipAddress": "203.0.113.42",
    "userAgent": "Mozilla/5.0 ...",
    "createdAt": "2026-02-20T14:30:00.000Z"
  }
}

Action Reference

Common action identifiers recorded by the system:

ActionResource TypeTrigger
booking.createdbookingNew booking created
booking.updatedbookingBooking details modified
booking.deletedbookingBooking cancelled / removed
invoice.createdinvoiceInvoice generated
invoice.updatedinvoiceInvoice edited
payment.recordedpaymentPayment received
expense.createdexpenseExpense entry added
guest.createdguestGuest registered
guest.updatedguestGuest details updated
room.createdroomRoom added
room.updatedroomRoom details modified
user.inviteduserUser invited to organization
user.role_changeduserUser role updated
settings.updatedsettingsOrganization settings changed

Error Responses

json
{
  "success": false,
  "message": "Descriptive error message"
}
StatusMeaning
400Invalid query parameters
401Unauthorized — missing or invalid token
403Forbidden — not a member of the org
404Log entry or org not found
500Internal server error

Released under the MIT License.