REST API Documentation
Programmatically manage databases, query metrics, trigger optimizations, and integrate DB24x7 into your workflows.
Overview
The DB24x7 REST API provides programmatic access to all platform features. Built on REST principles, it uses standard HTTP methods, JSON payloads, and returns HTTP response codes to indicate success or failure.
RESTful Design
Standard HTTP methods (GET, POST, PUT, PATCH, DELETE)
Secure Authentication
API keys and OAuth 2.0 for secure access
Versioned API
API versioning ensures backward compatibility
Official SDKs
Python, Node.js, and Go client libraries
Base URL: https://api.db24x7.com/v1
Authentication
API Key Authentication
The simplest way to authenticate is using an API key. Include your API key in the Authorization header as a Bearer token.
Step 1: Generate API Key
- Navigate to DB24x7 Dashboard → Settings → API Keys
- Click "Generate New API Key"
- Provide a descriptive name and set permissions (read/write)
- Copy the generated key (shown only once)
Step 2: Use in Requests
curl -X GET "https://api.db24x7.com/v1/databases" \
-H "Authorization: Bearer db24x7_sk_live_abc123def456ghi789jkl012mno345pqr678"Security Best Practices
- Never commit API keys to version control
- Store keys in environment variables or secure vaults
- Rotate keys regularly and revoke unused ones
- Use different keys for development and production
- Set minimum required permissions for each key
OAuth 2.0 Authentication
For applications that need to access DB24x7 on behalf of users, use OAuth 2.0 with the authorization code flow.
OAuth Flow
- Register your application in DB24x7 to get Client ID and Client Secret
- Redirect users to:
https://app.db24x7.com/oauth/authorize - Users authorize your application
- Receive authorization code at your redirect URI
- Exchange code for access token
- Use access token in API requests
Token Exchange Example
curl -X POST "https://api.db24x7.com/v1/oauth/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=authorization_code" \
-d "code=AUTH_CODE_HERE" \
-d "client_id=YOUR_CLIENT_ID" \
-d "client_secret=YOUR_CLIENT_SECRET" \
-d "redirect_uri=https://yourapp.com/callback"Endpoints Overview
The API is organized into logical resource groups:
Databases
Manage database connections and configurations
/databases/databases/databases/:id/databases/:id/databases/:idMetrics
Query performance metrics and time-series data
/databases/:id/metrics/databases/:id/metrics/history/databases/:id/queriesAlerts
Manage alert rules and view active alerts
/alerts/alerts/rules/alerts/:id/resolveOptimizations
Trigger and manage AI-powered optimizations
/databases/:id/optimize/optimizations/optimizations/:id/applyExample Requests
List All Databases
curl -X GET "https://api.db24x7.com/v1/databases" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"Response (200 OK)
{
"data": [
{
"id": "db_abc123",
"name": "production-postgres-01",
"type": "postgresql",
"version": "15.2",
"status": "healthy",
"created_at": "2026-01-15T10:30:00Z"
},
{
"id": "db_def456",
"name": "production-mysql-01",
"type": "mysql",
"version": "8.0.32",
"status": "warning",
"created_at": "2026-01-20T14:45:00Z"
}
],
"pagination": {
"total": 2,
"page": 1,
"per_page": 10
}
}Add New Database
curl -X POST "https://api.db24x7.com/v1/databases" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "staging-postgres-01",
"type": "postgresql",
"connection": {
"host": "db.staging.example.com",
"port": 5432,
"database": "app_staging",
"username": "db24x7_user",
"password": "secure_password",
"ssl": true
},
"monitoring": {
"enabled": true,
"interval_seconds": 60
}
}'Get Database Metrics
curl -X GET "https://api.db24x7.com/v1/databases/db_abc123/metrics?range=1h" \
-H "Authorization: Bearer YOUR_API_KEY"Response (200 OK)
{
"database_id": "db_abc123",
"timestamp": "2026-02-07T10:30:00Z",
"metrics": {
"cpu_usage": 45.3,
"memory_usage": 62.1,
"disk_usage": 58.7,
"connections": {
"active": 45,
"idle": 105,
"total": 150,
"max": 200
},
"throughput": {
"queries_per_second": 1250,
"transactions_per_second": 420
},
"latency": {
"avg_query_time_ms": 12.5,
"p95_query_time_ms": 45.2,
"p99_query_time_ms": 120.8
}
}
}Trigger Query Optimization
curl -X POST "https://api.db24x7.com/v1/databases/db_abc123/optimize" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query_id": "query_xyz789",
"auto_apply": false
}'Rate Limits
API rate limits are enforced to ensure fair usage and platform stability. Limits vary by plan:
Free Plan
For development and testing
Pro Plan
For production workloads
Enterprise Plan
Custom limits available
Rate Limit Headers
Each API response includes headers to help you track your rate limit status:
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 847
X-RateLimit-Reset: 1707305400Handling Rate Limit Errors
When you exceed the rate limit, you'll receive a 429 Too Many Requests response:
{
"error": {
"type": "rate_limit_exceeded",
"message": "Rate limit exceeded. Please retry after 1707305400",
"retry_after": 1707305400
}
}Implement exponential backoff in your client to handle rate limits gracefully.
Official SDKs
Use our official client libraries for easier integration:
PyPython SDK
Installation
pip install db24x7Usage Example
from db24x7 import Client
client = Client(api_key='YOUR_API_KEY')
# List all databases
databases = client.databases.list()
# Get metrics for a specific database
metrics = client.databases.get_metrics('db_abc123', range='1h')
# Trigger optimization
optimization = client.databases.optimize('db_abc123', query_id='query_xyz789')
print(f"Optimization ID: {optimization.id}")JSNode.js SDK
Installation
npm install @db24x7/sdkUsage Example
import { DB24x7Client } from '@db24x7/sdk';
const client = new DB24x7Client({
apiKey: 'YOUR_API_KEY'
});
// List all databases
const databases = await client.databases.list();
// Get metrics for a specific database
const metrics = await client.databases.getMetrics('db_abc123', {
range: '1h'
});
// Trigger optimization
const optimization = await client.databases.optimize('db_abc123', {
queryId: 'query_xyz789'
});
console.log(`Optimization ID: ${optimization.id}`);GoGo SDK
Installation
go get github.com/db24x7/go-sdkUsage Example
package main
import (
"fmt"
"github.com/db24x7/go-sdk"
)
func main() {
client := db24x7.NewClient("YOUR_API_KEY")
// List all databases
databases, err := client.Databases.List()
if err != nil {
panic(err)
}
// Get metrics for a specific database
metrics, err := client.Databases.GetMetrics("db_abc123", &db24x7.MetricsOptions{
Range: "1h",
})
// Trigger optimization
optimization, err := client.Databases.Optimize("db_abc123", &db24x7.OptimizeOptions{
QueryID: "query_xyz789",
})
fmt.Printf("Optimization ID: %s\n", optimization.ID)
}Error Handling
The API uses standard HTTP status codes and returns detailed error messages in JSON format:
200 OKSuccessRequest succeeded
400 Bad RequestClient ErrorInvalid request parameters or body
401 UnauthorizedAuth ErrorMissing or invalid API key
403 ForbiddenAuth ErrorAPI key lacks required permissions
404 Not FoundClient ErrorResource does not exist
429 Too Many RequestsRate LimitRate limit exceeded
500 Server ErrorServer ErrorInternal server error
Error Response Format
{
"error": {
"type": "invalid_request",
"message": "Database ID is required",
"param": "database_id",
"code": "missing_required_parameter"
}
}Best Practices
Recommendations
- Use HTTPS for all API requests
- Implement exponential backoff for retries
- Cache responses when appropriate to reduce API calls
- Use pagination for large result sets
- Monitor rate limit headers and adjust request frequency
- Use webhooks instead of polling for real-time updates
- Validate responses and handle errors gracefully
- Keep API keys secure and rotate them regularly