Skip to content

Audit Rail

Audit trails, compliance logging, and activity tracking.

The Audit Rail provides endpoints for comprehensive audit logging, activity tracking, and compliance reporting.

/api/v1/audit
GET /api/v1/audit/logs

List audit log entries.

Query Parameters:

ParameterTypeDescription
actionstringFilter by action type
entityTypestringFilter by entity type
entityIdstringFilter by entity ID
actorIdstringFilter by actor
fromstringStart timestamp
tostringEnd timestamp
pagenumberPage number
perPagenumberItems per page

Response:

{
"data": [
{
"logId": "log_abc123",
"timestamp": "2025-01-15T10:00:00Z",
"action": "CONTRACT_CREATED",
"entityType": "CONTRACT",
"entityId": "con_xyz",
"actor": {
"type": "USER",
"id": "user_123",
"email": "user@example.com"
},
"metadata": {
"contractType": "MURABAHA",
"amount": "500000.00"
},
"ipAddress": "192.168.1.100",
"userAgent": "Mozilla/5.0...",
"traceId": "trace_abc"
}
],
"pagination": {
"page": 1,
"total": 15000
}
}
GET /api/v1/audit/logs/:logId

Get single audit log entry with full details.

GET /api/v1/audit/entities/:entityType/:entityId/history

Get change history for an entity.

Response:

{
"data": [
{
"timestamp": "2025-01-15T10:00:00Z",
"action": "CREATED",
"actor": "user_123",
"changes": null
},
{
"timestamp": "2025-01-15T11:00:00Z",
"action": "UPDATED",
"actor": "user_456",
"changes": {
"status": {
"from": "DRAFT",
"to": "PENDING_APPROVAL"
}
}
}
]
}
POST /api/v1/audit/export

Export audit logs for compliance.

Request Body:

{
"format": "CSV",
"filter": {
"from": "2025-01-01T00:00:00Z",
"to": "2025-01-31T23:59:59Z",
"entityType": "CONTRACT"
},
"destination": {
"type": "EMAIL",
"email": "compliance@example.com"
}
}
GET /api/v1/audit/access-logs

Get data access logs (who accessed what).

Query Parameters:

ParameterTypeDescription
resourceTypestringFilter by resource type
accessTypestringREAD, WRITE, DELETE
actorIdstringFilter by actor
GET /api/v1/audit/login-history

Get authentication history.

Query Parameters:

ParameterTypeDescription
userIdstringFilter by user
statusstringSUCCESS, FAILED
fromstringStart date

Response:

{
"data": [
{
"timestamp": "2025-01-15T10:00:00Z",
"userId": "user_123",
"status": "SUCCESS",
"method": "PASSWORD",
"ipAddress": "192.168.1.100",
"location": "Riyadh, SA",
"device": "Chrome on Windows"
}
]
}
POST /api/v1/audit/reports

Generate compliance audit report.

Request Body:

{
"reportType": "COMPLIANCE_SUMMARY",
"period": {
"from": "2025-01-01",
"to": "2025-01-31"
},
"includeStats": true,
"format": "PDF"
}
GET /api/v1/audit/stats

Get audit statistics.

Response:

{
"data": {
"period": "2025-01",
"totalEvents": 150000,
"byAction": {
"CREATE": 25000,
"UPDATE": 80000,
"DELETE": 5000,
"READ": 40000
},
"byEntityType": {
"CONTRACT": 30000,
"CUSTOMER": 45000,
"PAYMENT": 50000
},
"uniqueActors": 250,
"failedLogins": 150
}
}
ActionDescription
CREATEEntity created
UPDATEEntity updated
DELETEEntity deleted
READEntity accessed
EXPORTData exported
LOGINUser logged in
LOGOUTUser logged out
APPROVEApproval action
REJECTRejection action
TypeDescription
USERHuman user
API_KEYAPI key access
SYSTEMSystem process
WEBHOOKWebhook trigger
EventDescription
audit.log.createdAudit log created
audit.export.completedExport completed
audit.suspicious.detectedSuspicious activity