Audit API

Machine-level audit trail management and activity monitoring. Track all system activities on a per-machine basis with detailed logging and analytics.

Audit TrailsMachine ScopedActivity Analytics

Base URL

https://sapienstream.com/api/v1/audit

Overview

The Audit API provides comprehensive logging and monitoring capabilities for tracking all system activities on a per-machine basis. Every operation is recorded with detailed metadata including timestamps, actors, resources, and before/after values for compliance and troubleshooting.

Important: All audit endpoints are machine-scoped, meaning you must provide a machine_id to access audit logs for that specific machine.

Endpoints

GET
/{machine_id}
List audit logs for a specific machine

Query Parameters

start_time- Start time for audit log query (ISO 8601)
end_time- End time for audit log query (ISO 8601)
actor- Filter by specific actor/user
action- Filter by action type
limit- Maximum results (default: 100, max: 1000)

Example Request

curl -X GET "https://sapienstream.com/api/v1/audit/machine_001?action=tag_write&limit=50" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Example Response

[
  {
    "id": "audit_20250125_001",
    "timestamp": "2025-01-25T10:30:00Z",
    "actor": "[email protected]",
    "action": "tag_write",
    "resource_type": "tag",
    "resource_id": "temperature_sensor_01",
    "machine_id": "machine_001",
    "before_value": {"value": 23.5},
    "after_value": {"value": 25.0},
    "severity": "info",
    "is_successful": true
  }
]
GET
/{machine_id}/{audit_id}
Get a specific audit log entry
curl -X GET "https://sapienstream.com/api/v1/audit/machine_001/audit_20250125_001" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"
GET
/{machine_id}/stats
Get audit statistics for a machine
curl -X GET "https://sapienstream.com/api/v1/audit/machine_001/stats" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Example Response

{
  "total_events": 1250,
  "success_rate": 98.5,
  "most_active_users": [
    {"user": "[email protected]", "count": 450}
  ],
  "most_common_actions": [
    {"action": "tag_read", "count": 800},
    {"action": "tag_write", "count": 300}
  ]
}
GET
/{machine_id}/actor/{actor}
Get audit logs for a specific actor
curl -X GET "https://sapienstream.com/api/v1/audit/machine_001/actor/[email protected]" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"
GET
/{machine_id}/user/{user_id}
Get audit logs for a specific user ID
curl -X GET "https://sapienstream.com/api/v1/audit/machine_001/user/user_123" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"
GET
/{machine_id}/errors
Get error summary for a machine
curl -X GET "https://sapienstream.com/api/v1/audit/machine_001/errors" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"
POST
/{machine_id}/export
Export audit logs (Coming Soon)
Coming Soon

This endpoint is planned but not yet implemented. Returns 501 Not Implemented.

Related Documentation