API Reference

Databases API

Programmatically manage your monitored database connections. Add new databases, configure audit settings, and monitor connection health through the REST API.

Base URL
https://api.dbaudit.ai/v1

Supported Databases

DB Audit supports monitoring for all major database platforms. Each database type has specific configuration options and audit capabilities.

PostgreSQL

11, 12, 13, 14, 15, 16

MySQL

5.7, 8.0, 8.4

SQL Server

2016, 2019, 2022

Oracle

12c, 18c, 19c, 21c, 23ai

MongoDB

5.0, 6.0, 7.0, 8.0

MariaDB

10.5, 10.6, 10.11, 11.x

Endpoints

MethodEndpointDescriptionScope
GET/v1/databasesList all monitored database connectionsread:databases
POST/v1/databasesAdd a new database connection for monitoringwrite:databases
GET/v1/databases/{id}Get details of a specific database connectionread:databases
PATCH/v1/databases/{id}Update database connection settingswrite:databases
DELETE/v1/databases/{id}Remove a database connection from monitoringwrite:databases
GET/v1/databases/{id}/statusGet real-time connection and audit statusread:databases
POST/v1/databases/{id}/testTest database connection credentialswrite:databases
GET/v1/databases

List Databases

Retrieve a paginated list of all database connections in your account. Supports filtering by status, type, and tags.

Query Parameters

statusFilter by connection status (connected, disconnected, pending, error)
typeFilter by database type (postgresql, mysql, sqlserver, oracle, mongodb)
tagsFilter by tags (comma-separated)
pagePage number (default: 1)
per_pageResults per page (default: 20, max: 100)
# List all monitored databases
curl -X GET "https://api.dbaudit.ai/v1/databases" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json"

# Response
{
  "data": [
    {
      "id": "db_abc123",
      "name": "Production PostgreSQL",
      "type": "postgresql",
      "host": "prod-db.example.com",
      "port": 5432,
      "status": "connected",
      "audit_status": "active",
      "created_at": "2024-01-15T10:30:00Z",
      "last_event_at": "2024-01-20T14:22:15Z"
    }
  ],
  "pagination": {
    "total": 12,
    "page": 1,
    "per_page": 20
  }
}
POST/v1/databases

Create Database Connection

Add a new database connection to your monitoring environment. The connection will be tested and validated before being activated.

Request Body

namerequiredHuman-readable name for the database
typerequiredDatabase type (postgresql, mysql, sqlserver, oracle, mongodb, mariadb)
hostrequiredDatabase server hostname or IP address
portrequiredDatabase server port number
databaserequiredName of the database to monitor
usernamerequiredUsername for database connection
passwordrequiredPassword for database connection (stored encrypted)
ssl_modeoptionalSSL connection mode (disable, require, verify-ca, verify-full)
tagsoptionalArray of tags for organization
audit_optionsoptionalAudit configuration object
# Add a new database connection
curl -X POST "https://api.dbaudit.ai/v1/databases" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Production PostgreSQL",
    "type": "postgresql",
    "host": "prod-db.example.com",
    "port": 5432,
    "database": "myapp",
    "username": "dbaudit_reader",
    "password": "secure_password",
    "ssl_mode": "verify-full",
    "ssl_ca": "-----BEGIN CERTIFICATE-----...",
    "tags": ["production", "critical"],
    "audit_options": {
      "capture_queries": true,
      "capture_results": false,
      "mask_sensitive_data": true
    }
  }'

# Response
{
  "id": "db_xyz789",
  "name": "Production PostgreSQL",
  "type": "postgresql",
  "status": "pending",
  "created_at": "2024-01-20T15:00:00Z"
}

Credential Security

Database credentials are encrypted at rest using AES-256 and never logged. For enhanced security, consider using IAM authentication or certificate-based auth where supported.

GET/v1/databases/{id}

Get Database Details

Retrieve detailed information about a specific database connection, including statistics, health metrics, and configuration.

# Get database details
curl -X GET "https://api.dbaudit.ai/v1/databases/db_abc123" \
  -H "Authorization: Bearer YOUR_API_KEY"

# Response
{
  "id": "db_abc123",
  "name": "Production PostgreSQL",
  "type": "postgresql",
  "host": "prod-db.example.com",
  "port": 5432,
  "database": "myapp",
  "username": "dbaudit_reader",
  "ssl_mode": "verify-full",
  "status": "connected",
  "audit_status": "active",
  "stats": {
    "events_today": 15420,
    "events_this_week": 98540,
    "alerts_pending": 3,
    "policies_active": 8
  },
  "health": {
    "latency_ms": 12,
    "last_heartbeat": "2024-01-20T15:30:00Z"
  },
  "created_at": "2024-01-15T10:30:00Z",
  "updated_at": "2024-01-20T12:00:00Z"
}
PATCH/v1/databases/{id}

Update Database

Update the configuration of an existing database connection. Only include fields you want to change.

# Update database settings
curl -X PATCH "https://api.dbaudit.ai/v1/databases/db_abc123" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Production PostgreSQL (Primary)",
    "tags": ["production", "critical", "pci-dss"],
    "audit_options": {
      "capture_queries": true,
      "capture_results": true,
      "mask_sensitive_data": true,
      "retention_days": 90
    }
  }'
DELETE/v1/databases/{id}

Delete Database

Remove a database connection from monitoring. This action does not delete historical audit data, which is retained according to your retention policy.

# Remove a database from monitoring
curl -X DELETE "https://api.dbaudit.ai/v1/databases/db_abc123" \
  -H "Authorization: Bearer YOUR_API_KEY"

# Response: 204 No Content

Caution

Deleting a database stops all monitoring and alerting. Active policies will be deactivated. This action cannot be undone.

GET/v1/databases/{id}/status

Get Database Status

Retrieve real-time status information including connection health, collector metrics, and the most recent audit event.

# Get real-time database status
curl -X GET "https://api.dbaudit.ai/v1/databases/db_abc123/status" \
  -H "Authorization: Bearer YOUR_API_KEY"

# Response
{
  "id": "db_abc123",
  "connection_status": "connected",
  "audit_status": "active",
  "collector": {
    "version": "2.4.1",
    "uptime_seconds": 864000,
    "events_per_second": 42.5
  },
  "health_checks": {
    "connectivity": "healthy",
    "permissions": "healthy",
    "latency": "healthy",
    "disk_space": "warning"
  },
  "last_event": {
    "timestamp": "2024-01-20T15:30:45Z",
    "type": "query",
    "user": "app_user"
  }
}
POST/v1/databases/{id}/test

Test Connection

Test the database connection and verify that the configured credentials have the required permissions for auditing.

# Test database connection
curl -X POST "https://api.dbaudit.ai/v1/databases/db_abc123/test" \
  -H "Authorization: Bearer YOUR_API_KEY"

# Response
{
  "success": true,
  "latency_ms": 15,
  "version": "PostgreSQL 16.1",
  "permissions": {
    "select": true,
    "pg_read_all_stats": true,
    "pg_monitor": true
  },
  "warnings": []
}

Database Object Schema

The database object contains the following fields:

FieldTypeDescription
idstringUnique identifier for the database connection
namestringHuman-readable name for the database
typestringDatabase type (postgresql, mysql, sqlserver, oracle, mongodb, mariadb)
hoststringDatabase server hostname or IP address
portintegerDatabase server port number
databasestringName of the database to monitor
usernamestringUsername for database connection
ssl_modestringSSL/TLS connection mode
statusstringConnection status (connected, disconnected, pending, error)
audit_statusstringAudit status (active, paused, initializing)
tagsarrayCustom tags for organization and filtering
created_atdatetimeTimestamp when the connection was created
updated_atdatetimeTimestamp of last update

SDK Examples

Use our official SDKs for simplified database management in your preferred language.

Python

import dbaudit

client = dbaudit.Client()

# List all databases
databases = client.databases.list()
for db in databases:
    print(f"{db.name}: {db.status}")

# Add a new database
new_db = client.databases.create(
    name="Production PostgreSQL",
    type="postgresql",
    host="prod-db.example.com",
    port=5432,
    database="myapp",
    username="dbaudit_reader",
    password="secure_password",
    ssl_mode="verify-full"
)

# Get database status
status = client.databases.get_status("db_abc123")
print(f"Events per second: {status.collector.events_per_second}")

Node.js

import { DBaudit } from '@dbaudit/sdk';

const client = new DBaudit();

// List all databases
const databases = await client.databases.list();
databases.forEach(db => {
  console.log(`${db.name}: ${db.status}`);
});

// Add a new database
const newDb = await client.databases.create({
  name: 'Production PostgreSQL',
  type: 'postgresql',
  host: 'prod-db.example.com',
  port: 5432,
  database: 'myapp',
  username: 'dbaudit_reader',
  password: 'secure_password',
  sslMode: 'verify-full',
});

// Get database status
const status = await client.databases.getStatus('db_abc123');
console.log(`Events per second: ${status.collector.eventsPerSecond}`);

Error Responses

Common error responses for the Databases API:

400

Bad Request

Invalid request body or missing required fields.

404

Not Found

Database connection with the specified ID does not exist.

409

Conflict

A database with the same host/port/database combination already exists.

422

Unprocessable Entity

Connection test failed. Check credentials and network connectivity.

Related Resources

Explore more API endpoints and database-specific documentation:

Start Monitoring Your Databases

Add your first database connection and start receiving security insights within minutes.