The API (Application Programming Interface) provides programmatic access to all monitoring system functionality, allowing you to integrate monitoring capabilities into your applications, automate tasks, build custom dashboards, and create workflows that interact with your monitoring data. The API follows REST principles and returns data in JSON format.
Authorization: Bearer YOUR_API_KEY
All API requests are made to:
https://yourdomain.com/api/
curl -X POST "https://yourdomain.com/api/monitors" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Company Website",
"type": "website",
"target": "https://example.com",
"check_interval": 300,
"notifications": [1, 2, 3]
}'
curl -X GET "https://yourdomain.com/api/monitors/123" \ -H "Authorization: Bearer YOUR_API_KEY"
curl -X PUT "https://yourdomain.com/api/monitors/123" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"check_interval": 600,
"is_enabled": true
}'
curl -X GET "https://yourdomain.com/api/heartbeats/abc123def456/ping" \ -H "Authorization: Bearer YOUR_API_KEY"
curl -X POST "https://yourdomain.com/api/heartbeats" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Daily Backup Job",
"run_interval": 86400,
"grace_period": 3600
}'
curl -X PUT "https://yourdomain.com/api/status-pages/456" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"incident_status": "investigating",
"incident_message": "We are investigating reports of slow response times."
}'
curl -X GET "https://yourdomain.com/api/monitors/123/logs?start_date=2024-01-01&end_date=2024-01-31" \ -H "Authorization: Bearer YOUR_API_KEY"
curl -X GET "https://yourdomain.com/api/incidents?format=csv&start_date=2024-01-01" \ -H "Authorization: Bearer YOUR_API_KEY"
pip install monitoring-api-sdk
from monitoring_api import Client
client = Client(api_key='YOUR_API_KEY')
monitors = client.monitors.list()
print(f"Found {len(monitors)} monitors")
npm install monitoring-api-sdk
const MonitoringAPI = require('monitoring-api-sdk');
const client = new MonitoringAPI('YOUR_API_KEY');
async function getMonitors() {
const monitors = await client.monitors.list();
console.log(`Found ${monitors.length} monitors`);
}
composer require monitoring/api-sdk
use Monitoring\API\Client;
$client = new Client('YOUR_API_KEY');
$monitors = $client->monitors()->list();
echo "Found " . count($monitors) . " monitors";
# GitHub Actions example
- name: Create deployment monitor
run: |
curl -X POST "https://yourdomain.com/api/monitors" \
-H "Authorization: Bearer ${{ secrets.MONITORING_API_KEY }}" \
-H "Content-Type: application/json" \
-d '{
"name": "Staging Environment - Build ${{ github.sha }}",
"type": "website",
"target": "https://staging-${{ github.sha }}.example.com"
}'
# Wait for deployment to stabilize, then verify monitoring sleep 60 monitor_status=$(curl -s -H "Authorization: Bearer $API_KEY" \ "https://yourdomain.com/api/monitors/123" | jq -r '.is_ok') if [ "$monitor_status" = "true" ]; then echo "Deployment successful - monitoring shows all systems operational" else echo "Deployment may have issues - monitoring shows problems" exit 1 fi
resource "monitoring_monitor" "web_server" {
name = "Web Server ${var.environment}"
type = "website"
target = "https://${var.domain}"
interval = 300
notifications = [
monitoring_notification_handler.email.id,
monitoring_notification_handler.slack.id
]
}
- name: Create application monitor
uri:
url: "https://yourdomain.com/api/monitors"
method: POST
headers:
Authorization: "Bearer {{ monitoring_api_key }}"
Content-Type: "application/json"
body_format: json
body:
name: "{{ app_name }} - {{ environment }}"
type: "website"
target: "{{ app_url }}"
check_interval: 300
import React, { useEffect, useState } from 'react';
function MonitorStatus() {
const [monitors, setMonitors] = useState([]);
useEffect(() => {
fetch('/api/monitors', {
headers: {
'Authorization': `Bearer ${process.env.REACT_APP_API_KEY}`
}
})
.then(response => response.json())
.then(data => setMonitors(data));
}, []);
return (
<div>
{monitors.map(monitor => (
<div key={monitor.id} className={monitor.is_ok ? 'online' : 'offline'}>
{monitor.name}: {monitor.is_ok ? 'Online' : 'Offline'}
</div>
))}
</div>
);
}
{
"event": "monitor.down",
"timestamp": "2024-01-15T10:30:00Z",
"monitor": {
"id": 123,
"name": "Main Website",
"type": "website",
"target": "https://example.com",
"status": "down"
},
"incident": {
"id": 456,
"started_at": "2024-01-15T10:29:45Z",
"error_message": "Connection timeout"
}
}
// Express.js webhook handler
app.post('/webhooks/monitoring', (req, res) => {
const event = req.body;
switch(event.event) {
case 'monitor.down':
handleMonitorDown(event.monitor, event.incident);
break;
case 'monitor.up':
handleMonitorUp(event.monitor);
break;
case 'incident.resolved':
handleIncidentResolved(event.incident);
break;
}
res.status(200).send('OK');
});
{
"status": "success",
"data": {
"monitor": {
"id": 123,
"name": "Website Monitor",
"type": "website",
"target": "https://example.com",
"is_ok": true,
"uptime": 99.95,
"response_time": 245
}
},
"meta": {
"timestamp": "2024-01-15T10:30:00Z"
}
}
{
"status": "error",
"error": {
"code": "VALIDATION_ERROR",
"message": "Invalid monitor configuration",
"details": {
"target": ["Target URL is required"],
"type": ["Monitor type must be one of: website, ping, port"]
}
},
"meta": {
"timestamp": "2024-01-15T10:30:00Z"
}
}
{
"status": "success",
"data": {
"monitors": [...],
"pagination": {
"current_page": 1,
"per_page": 25,
"total_pages": 4,
"total_items": 87,
"has_next": true,
"has_previous": false
}
}
}
curl -X PUT "https://yourdomain.com/api/monitors/bulk" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"monitor_ids": [123, 124, 125],
"updates": {
"check_interval": 600,
"is_enabled": true
}
}'
const socket = new WebSocket('wss://yourdomain.com/api/ws');
socket.onopen = function() {
socket.send(JSON.stringify({
'auth': 'YOUR_API_KEY',
'subscribe': ['monitor.status', 'incident.updates']
}));
};
socket.onmessage = function(event) {
const data = JSON.parse(event.data);
console.log('Real-time update:', data);
};
GET /api/monitors?project_id=123&status=down&created_after=2024-01-01&sort=uptime:desc