Triggers API
REST API for managing collection triggers that create background jobs on document changes.
GET
/_api/database/:db/triggers
List all triggers in the database.
Response
{
"triggers": [
{
"_key": "550e8400-e29b-41d4-a716-446655440000",
"_rev": "1234567890",
"name": "send_welcome_email",
"collection": "users",
"events": ["insert"],
"script_path": "triggers/welcome_email.lua",
"queue": "emails",
"priority": 10,
"max_retries": 3,
"enabled": true,
"created_at": 1705312800,
"updated_at": 1705312800
}
],
"total": 1
}
cURL Example
curl -X GET "http://localhost:6745/_api/database/mydb/triggers" \
-H "Authorization: Bearer $TOKEN"
POST
/_api/database/:db/triggers
Create a new trigger for a collection.
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | Human-readable trigger name |
| collection | string | Yes | Collection to watch (must exist) |
| events | array | Yes | Events: "insert", "update", "delete" |
| script_path | string | Yes | Path to Lua script in _scripts |
| queue | string | No | Queue name (default: "default") |
| priority | integer | No | Job priority (default: 0) |
| max_retries | integer | No | Max retry attempts (default: 5) |
| enabled | boolean | No | Active state (default: true) |
cURL Example
curl -X POST "http://localhost:6745/_api/database/mydb/triggers" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "send_welcome_email",
"collection": "users",
"events": ["insert"],
"script_path": "triggers/welcome_email.lua",
"queue": "emails",
"priority": 10,
"max_retries": 3,
"enabled": true
}'
Response
{
"_key": "550e8400-e29b-41d4-a716-446655440000",
"name": "send_welcome_email",
"collection": "users",
"events": ["insert"],
"script_path": "triggers/welcome_email.lua",
"queue": "emails",
"priority": 10,
"max_retries": 3,
"enabled": true,
"created_at": 1705312800,
"updated_at": 1705312800
}
GET
/_api/database/:db/triggers/:id
Get a specific trigger by its ID.
Path Parameters
| Parameter | Description |
|---|---|
| db | Database name |
| id | Trigger ID (_key) |
cURL Example
curl -X GET "http://localhost:6745/_api/database/mydb/triggers/550e8400-e29b-41d4-a716-446655440000" \
-H "Authorization: Bearer $TOKEN"
PUT
/_api/database/:db/triggers/:id
Update an existing trigger. Only provided fields will be updated.
cURL Example
curl -X PUT "http://localhost:6745/_api/database/mydb/triggers/550e8400-e29b-41d4-a716-446655440000" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"events": ["insert", "update"],
"priority": 20
}'
DELETE
/_api/database/:db/triggers/:id
Delete a trigger.
cURL Example
curl -X DELETE "http://localhost:6745/_api/database/mydb/triggers/550e8400-e29b-41d4-a716-446655440000" \
-H "Authorization: Bearer $TOKEN"
Response
{ "success": true }
POST
/_api/database/:db/triggers/:id/toggle
Toggle a trigger's enabled/disabled state.
cURL Example
curl -X POST "http://localhost:6745/_api/database/mydb/triggers/550e8400-e29b-41d4-a716-446655440000/toggle" \
-H "Authorization: Bearer $TOKEN"
Response
Returns the updated trigger with the new enabled state.
{
"_key": "550e8400-e29b-41d4-a716-446655440000",
"name": "send_welcome_email",
"enabled": false,
...
}
GET
/_api/database/:db/collections/:coll/triggers
List all triggers for a specific collection.
Path Parameters
| Parameter | Description |
|---|---|
| db | Database name |
| coll | Collection name |
cURL Example
curl -X GET "http://localhost:6745/_api/database/mydb/collections/users/triggers" \
-H "Authorization: Bearer $TOKEN"