Scheduled Tasks API
Create and manage cron-based scheduled tasks that trigger agents, workflows, and webhooks.
Overview
Scheduled tasks let you run automated actions on a recurring schedule using cron expressions. Each task can trigger an agent chat, execute a workflow, or call a webhook at the specified interval.
Action Types
| Type | Description |
|---|---|
agent_chat | Send a message to an agent and optionally store the response |
workflow_execution | Execute a workflow with predefined input data |
webhook_call | Send an HTTP request to an external URL |
Endpoints
List Scheduled Tasks
GET /api/v1/scheduled-tasks
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
page | integer | Page number (default: 1) |
per_page | integer | Items per page (default: 20) |
enabled | boolean | Filter by enabled status |
action_type | string | Filter by action type |
Response:
json{ "data": [ { "id": "st_abc123", "name": "Daily Sales Report", "cron": "0 9 * * 1-5", "action_type": "workflow_execution", "action_config": { "workflow_id": "wf_abc123", "input": { "report_type": "daily" } }, "enabled": true, "last_run_at": "2026-01-15T09:00:00Z", "next_run_at": "2026-01-16T09:00:00Z", "created_at": "2026-01-01T10:00:00Z" } ], "total": 5, "page": 1, "per_page": 20 }
Create Scheduled Task
POST /api/v1/scheduled-tasks
Request Body:
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Display name for the task |
cron | string | Yes | Cron expression (5-field format) |
action_type | string | Yes | agent_chat, workflow_execution, or webhook_call |
action_config | object | Yes | Action-specific configuration (see below) |
enabled | boolean | No | Enable immediately (default: true) |
timezone | string | No | IANA timezone (default: UTC) |
description | string | No | Human-readable description |
Action Config: agent_chat
| Field | Type | Required | Description |
|---|---|---|---|
agent_id | string | Yes | Agent to send the message to |
message | string | Yes | Message content |
store_response | boolean | No | Save the agent response (default: false) |
Action Config: workflow_execution
| Field | Type | Required | Description |
|---|---|---|---|
workflow_id | string | Yes | Workflow to execute |
input | object | No | Input data for the workflow |
Action Config: webhook_call
| Field | Type | Required | Description |
|---|---|---|---|
url | string | Yes | URL to call |
method | string | No | HTTP method (default: POST) |
headers | object | No | Custom headers |
body | object | No | Request body |
Example -- Daily workflow at 9 AM on weekdays:
bashcurl -X POST /api/v1/scheduled-tasks \ -H "Authorization: Bearer your_api_key" \ -H "Content-Type: application/json" \ -d '{ "name": "Daily Sales Report", "cron": "0 9 * * 1-5", "timezone": "America/New_York", "action_type": "workflow_execution", "action_config": { "workflow_id": "wf_abc123", "input": { "report_type": "daily" } }, "enabled": true }'
Example -- Hourly agent check-in:
bashcurl -X POST /api/v1/scheduled-tasks \ -H "Authorization: Bearer your_api_key" \ -H "Content-Type: application/json" \ -d '{ "name": "Hourly System Check", "cron": "0 * * * *", "action_type": "agent_chat", "action_config": { "agent_id": "agent_abc123", "message": "Run a system health check and report any issues.", "store_response": true } }'
Example -- Weekly webhook ping:
bashcurl -X POST /api/v1/scheduled-tasks \ -H "Authorization: Bearer your_api_key" \ -H "Content-Type: application/json" \ -d '{ "name": "Weekly Analytics Export", "cron": "0 2 * * 0", "action_type": "webhook_call", "action_config": { "url": "https://analytics.yourcompany.com/export", "method": "POST", "headers": { "X-API-Key": "your_analytics_key" }, "body": { "period": "weekly" } } }'
Get Scheduled Task
GET /api/v1/scheduled-tasks/:id
Update Scheduled Task
PUT /api/v1/scheduled-tasks/:id
Accepts the same fields as creation. Only provided fields are updated.
Delete Scheduled Task
DELETE /api/v1/scheduled-tasks/:id
Toggle Task (Enable/Disable)
POST /api/v1/scheduled-tasks/:id/toggle
Toggles the enabled state of the task.
Response:
json{ "id": "st_abc123", "enabled": false, "next_run_at": null }
Execution History
GET /api/v1/scheduled-tasks/:id/executions
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
page | integer | Page number |
per_page | integer | Items per page |
status | string | Filter: success, failed, running |
Response:
json{ "data": [ { "id": "ste_abc123", "task_id": "st_abc123", "status": "success", "started_at": "2026-01-15T09:00:00Z", "completed_at": "2026-01-15T09:00:12Z", "duration_ms": 12000, "result": { "workflow_execution_id": "exec_xyz789", "output": { "report_url": "https://..." } } }, { "id": "ste_def456", "task_id": "st_abc123", "status": "failed", "started_at": "2026-01-14T09:00:00Z", "completed_at": "2026-01-14T09:00:05Z", "duration_ms": 5000, "error": "Workflow wf_abc123 not found" } ], "total": 30, "page": 1, "per_page": 20 }
Preview Next Run Times
Preview when a cron expression will fire next without creating a task.
POST /api/v1/scheduled-tasks/preview
Request Body:
| Field | Type | Required | Description |
|---|---|---|---|
cron | string | Yes | Cron expression to preview |
timezone | string | No | IANA timezone (default: UTC) |
count | integer | No | Number of future runs to show (default: 5, max: 20) |
bashcurl -X POST /api/v1/scheduled-tasks/preview \ -H "Authorization: Bearer your_api_key" \ -H "Content-Type: application/json" \ -d '{ "cron": "0 9 * * 1-5", "timezone": "America/New_York", "count": 5 }'
Response:
json{ "cron": "0 9 * * 1-5", "timezone": "America/New_York", "next_runs": [ "2026-01-16T09:00:00-05:00", "2026-01-19T09:00:00-05:00", "2026-01-20T09:00:00-05:00", "2026-01-21T09:00:00-05:00", "2026-01-22T09:00:00-05:00" ], "description": "At 09:00 AM, Monday through Friday" }
Cron Expression Reference
Cron expressions use the standard 5-field format:
┌───────── minute (0-59)
│ ┌───────── hour (0-23)
│ │ ┌───────── day of month (1-31)
│ │ │ ┌───────── month (1-12)
│ │ │ │ ┌───────── day of week (0-6, Sun=0)
│ │ │ │ │
* * * * *
Common Examples
| Expression | Description |
|---|---|
* * * * * | Every minute |
0 * * * * | Every hour at :00 |
0 9 * * * | Every day at 9:00 AM |
0 9 * * 1-5 | Weekdays at 9:00 AM |
0 0 * * 0 | Every Sunday at midnight |
0 9,17 * * * | Every day at 9:00 AM and 5:00 PM |
*/15 * * * * | Every 15 minutes |
0 0 1 * * | First day of every month at midnight |
0 6 * * 1 | Every Monday at 6:00 AM |
Error Codes
| Code | Description |
|---|---|
invalid_cron | The cron expression is malformed or invalid |
task_not_found | Scheduled task does not exist |
action_config_invalid | Action configuration is missing required fields |
agent_not_found | The agent referenced in action_config does not exist |
workflow_not_found | The workflow referenced in action_config does not exist |
max_tasks_reached | Tenant has reached the maximum number of scheduled tasks |