SQL API
Execute SQL queries on the agent database.
Endpoints
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/agents/{id}/sql/schema | Get database schema |
| POST | /api/agents/{id}/sql/execute | Execute query |
Get Schema
bash
GET /api/agents/{id}/sql/schemaResponse
json
{
"tables": [
{
"name": "workflows",
"columns": [
{ "name": "id", "type": "TEXT", "nullable": false },
{ "name": "name", "type": "TEXT", "nullable": false },
{ "name": "status", "type": "TEXT", "nullable": true }
]
}
]
}Execute Query
bash
POST /api/agents/{id}/sql/execute
Content-Type: application/jsonRequest Body
json
{
"query": "SELECT id, name FROM workflows LIMIT 10",
"params": []
}Response
json
{
"columns": ["id", "name"],
"rows": [
["workflow-1", "Email Notification"],
["workflow-2", "Data Sync"]
],
"row_count": 2,
"duration_ms": 5
}Allowed Operations
| Operation | Allowed |
|---|---|
| SELECT | Yes |
| INSERT | Yes |
| UPDATE | Yes |
| DELETE | Yes |
| PRAGMA | Yes |
| EXPLAIN | Yes |
| CREATE | No |
| DROP | No |
| ALTER | No |
Parameterized Queries
Use ? placeholders:
json
{
"query": "SELECT * FROM contacts WHERE email = ?",
"params": ["john@example.com"]
}Errors
| Code | Description |
|---|---|
| 400 | Invalid query |
| 403 | Forbidden operation |
| 500 | Execution error |