Skip to main content
All audit log endpoints require admin role authentication.

Get Audit Logs

Retrieve audit logs with optional filtering by user, table, or date range.

Query Parameters

user_id
string
Filter logs by user ID
table_name
string
Filter logs by table name (e.g., “products”, “inventory”)
start_date
string
Start date for date range filter (format: YYYY-MM-DD)
end_date
string
End date for date range filter (format: YYYY-MM-DD)
skip
integer
default:"0"
Number of records to skip for pagination
limit
integer
default:"100"
Maximum number of records to return

Response

status
string
Operation status (success or error)
count
integer
Number of audit logs returned
logs
array
Array of audit log entries
curl -X GET "https://api.example.com/api/v1/audit/logs?skip=0&limit=50" \
  -H "Authorization: Bearer YOUR_ADMIN_TOKEN"
{
  "status": "success",
  "count": 2,
  "logs": [
    {
      "id": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
      "user_id": "550e8400-e29b-41d4-a716-446655440000",
      "user_name": "admin",
      "action": "UPDATE",
      "table_name": "products",
      "record_id": "prod-12345",
      "old_values": {
        "quantity": 100,
        "price": 29.99
      },
      "new_values": {
        "quantity": 85,
        "price": 29.99
      },
      "description": "Updated product quantity after sale",
      "timestamp": "2024-03-04T14:23:45Z"
    },
    {
      "id": "b2c3d4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e",
      "user_id": "660e8400-e29b-41d4-a716-446655440001",
      "user_name": "warehouse_manager",
      "action": "CREATE",
      "table_name": "inventory",
      "record_id": "inv-67890",
      "old_values": null,
      "new_values": {
        "product_id": "prod-12345",
        "warehouse_id": "wh-001",
        "quantity": 500
      },
      "description": "Added new inventory batch",
      "timestamp": "2024-03-04T10:15:30Z"
    }
  ]
}

Get Audit Log by ID

Retrieve detailed information about a specific audit log entry.

Path Parameters

log_id
string
required
Unique identifier of the audit log

Response

status
string
Operation status (success or error)
log
object
Detailed audit log object including IP address
curl -X GET "https://api.example.com/api/v1/audit/logs/a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d" \
  -H "Authorization: Bearer YOUR_ADMIN_TOKEN"
{
  "status": "success",
  "log": {
    "id": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
    "user_id": "550e8400-e29b-41d4-a716-446655440000",
    "user_name": "admin",
    "action": "UPDATE",
    "table_name": "products",
    "record_id": "prod-12345",
    "old_values": {
      "quantity": 100,
      "price": 29.99
    },
    "new_values": {
      "quantity": 85,
      "price": 29.99
    },
    "description": "Updated product quantity after sale",
    "ip_address": "192.168.1.100",
    "timestamp": "2024-03-04T14:23:45Z"
  }
}

Create Audit Log

Manually create an audit log entry. This is typically used by system processes to record custom actions.

Request Body

user_id
string
required
ID of the user performing the action
user_name
string
Username of the user (optional)
action
string
required
Type of action: CREATE, UPDATE, DELETE, or READ
table_name
string
required
Name of the database table affected
record_id
string
required
ID of the record affected by the action
old_values
object
Previous values (for UPDATE/DELETE actions)
new_values
object
New values (for CREATE/UPDATE actions)
description
string
Human-readable description of the action
ip_address
string
IP address from which the action was performed

Response

status
string
Operation status (success or error)
id
string
ID of the created audit log entry
curl -X POST "https://api.example.com/api/v1/audit/logs" \
  -H "Authorization: Bearer YOUR_ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "user_id": "550e8400-e29b-41d4-a716-446655440000",
    "user_name": "admin",
    "action": "DELETE",
    "table_name": "products",
    "record_id": "prod-99999",
    "old_values": {
      "name": "Obsolete Product",
      "quantity": 0
    },
    "description": "Removed discontinued product",
    "ip_address": "192.168.1.100"
  }'
{
  "status": "success",
  "id": "c3d4e5f6-a7b8-4c9d-0e1f-2a3b4c5d6e7f"
}

Get Audit Summary

Retrieve aggregated statistics about audit logs, grouped by table, user, and action type.

Response

status
string
Operation status (success or error)
total_logs
integer
Total number of audit log entries
by_table
object
Count of actions per table name
by_user
object
Count of actions per user
by_action
object
Count of actions per action type (CREATE, UPDATE, DELETE, READ)
curl -X GET "https://api.example.com/api/v1/audit/summary" \
  -H "Authorization: Bearer YOUR_ADMIN_TOKEN"
{
  "status": "success",
  "total_logs": 1543,
  "by_table": {
    "products": 823,
    "inventory": 456,
    "warehouses": 189,
    "users": 75
  },
  "by_user": {
    "admin": 412,
    "warehouse_manager": 687,
    "operator_1": 298,
    "operator_2": 146
  },
  "by_action": {
    "CREATE": 345,
    "UPDATE": 982,
    "DELETE": 87,
    "READ": 129
  }
}

Action Types

Audit logs track the following action types:
Records the creation of new records. The new_values field contains the initial data of the created record.
Records modifications to existing records. Both old_values and new_values are populated to show what changed.
Records deletion of records. The old_values field contains the data that was deleted.
Records access to sensitive data. Used for compliance and security monitoring.

Common Tables

Audit logs commonly track changes to these tables:
  • products - Product catalog changes
  • inventory - Stock level modifications
  • warehouses - Warehouse configuration changes
  • users - User account modifications
  • movements - Inventory movement records
  • transactions - Transaction history

Build docs developers (and LLMs) love