Schedules API
Create and manage scheduled tasks.
List Schedules
GET /schedulesQuery Parameters
| Parameter | Type | Description |
|---|---|---|
machine_id | string | Filter by machine |
enabled | boolean | Filter by status |
limit | number | Results per page |
offset | number | Pagination offset |
Response
{
"data": [
{
"id": "sched_abc123",
"name": "Daily Backup",
"machine_id": "mach_xyz789",
"command": "pg_dump mydb > /backup/db.sql",
"cron": "0 3 * * *",
"enabled": true,
"timezone": "UTC",
"next_run": "2024-01-21T03:00:00Z",
"last_run": {
"at": "2024-01-20T03:00:00Z",
"exit_code": 0,
"duration": 15000
},
"created_at": "2024-01-15T10:30:00Z"
}
],
"meta": {
"total": 10,
"limit": 20,
"offset": 0
}
}Get Schedule
GET /schedules/:idResponse
{
"data": {
"id": "sched_abc123",
"name": "Daily Backup",
"description": "Backup production database every night",
"machine_id": "mach_xyz789",
"command": "pg_dump mydb > /backup/db.sql",
"cron": "0 3 * * *",
"enabled": true,
"timezone": "UTC",
"timeout": 300000,
"notify": {
"on_success": false,
"on_failure": true
},
"next_run": "2024-01-21T03:00:00Z",
"created_at": "2024-01-15T10:30:00Z",
"updated_at": "2024-01-18T14:20:00Z"
}
}Create Schedule
POST /schedulesRequest Body
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Schedule name |
machine_id | string | Yes | Target machine |
command | string | Yes | Command to run |
cron | string | Yes | Cron expression |
enabled | boolean | No | Default: true |
timezone | string | No | Default: UTC |
timeout | number | No | Timeout in ms |
notify | object | No | Notification settings |
Example
curl -X POST https://api.cmdop.com/v1/schedules \
-H "Authorization: Bearer TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Daily Backup",
"machine_id": "mach_xyz789",
"command": "pg_dump mydb > /backup/db.sql",
"cron": "0 3 * * *",
"timezone": "America/New_York",
"notify": {
"on_failure": true
}
}'Update Schedule
PATCH /schedules/:idRequest Body
{
"name": "Updated Name",
"cron": "0 4 * * *",
"enabled": false
}Delete Schedule
DELETE /schedules/:idResponse
{
"data": {
"deleted": true
}
}Run Now
Trigger schedule immediately:
POST /schedules/:id/runResponse
{
"data": {
"command_id": "cmd_xyz789",
"status": "running"
}
}Schedule History
GET /schedules/:id/historyQuery Parameters
| Parameter | Type | Description |
|---|---|---|
since | string | ISO timestamp |
limit | number | Results per page |
Response
{
"data": [
{
"id": "run_abc123",
"started_at": "2024-01-20T03:00:00Z",
"finished_at": "2024-01-20T03:00:15Z",
"exit_code": 0,
"duration": 15000,
"stdout": "...",
"stderr": ""
}
],
"meta": {
"total": 30,
"limit": 20,
"offset": 0
}
}