Webhooks
Send an HTTP POST to any URL when documents change, with a body built from a Handlebars template, and inspect every delivery.
A webhook posts to a URL whenever a change happens in a collection, for example when a document is inserted into a bucket. Use webhooks to notify Slack, start a CI build or call another service, without writing a function.

Create a webhook
curl -X POST https://api.example.com/api/webhook \
-H "Authorization: IDENTITY <token>" -H "Content-Type: application/json" \
-d '{
"title": "Notify Slack on new post",
"url": "https://hooks.slack.com/services/T000/B000/XXXX",
"body": "{\"text\": \"New post: {{document.slug}}\"}",
"trigger": {
"name": "database",
"active": true,
"options": {"collection": "bucket_6b0b1968a5611972c29c25f7", "type": "INSERT"}
}
}'| Field | Description |
|---|---|
title | Name shown in the panel. |
url | Where to send the request. |
body | A Handlebars template for the request body. |
trigger.name | Always database. |
trigger.active | Pause the webhook with false. |
trigger.options.collection | The collection to watch. Bucket data is stored in bucket_<bucketId>. |
trigger.options.type | INSERT, UPDATE, REPLACE or DELETE. |
GET /webhook/collections lists the collections you can watch, with readable names for buckets:
[{"id": "bucket_6b0b1968a5611972c29c25f7", "slug": "Posts"}, {"id": "identity", "slug": "identity"}]The request
Spica sends a POST with Content-Type: application/json and User-Agent: Spica/Webhooks; (https://spicaengine.com/docs/guide/webhook). The body template is rendered with:
| Variable | Contents |
|---|---|
type | The operation: insert, update, replace or delete. |
documentKey | The id of the document. |
document | The document after the change, or before it for deletes. |
Use the toJSON helper with triple braces to embed objects:
{"event": "{{type}}", "id": "{{documentKey}}", "post": {{{ toJSON document }}}}Templates are rendered in strict mode: referencing a missing property fails the delivery and records the error.
Delivery logs
Every delivery is logged with the request, the response status and body, and whether it succeeded (status below 400).
| Endpoint | Description |
|---|---|
GET /webhook/logs?webhook=<id> | Logs of a webhook. Filter with succeed=true or false, begin, end, skip, limit. |
DELETE /webhook/logs/:id | Delete one log entry. |
DELETE /webhook/logs | Clear logs. |
Manage webhooks
| Endpoint | Action |
|---|---|
GET /webhook | webhook:index |
GET /webhook/:id | webhook:show |
POST /webhook | webhook:create |
PUT /webhook/:id | webhook:update |
DELETE /webhook/:id | webhook:delete |
Webhooks or functions?
| Use a webhook when | Use a function when |
|---|---|
| You only forward the change to a URL. | You need logic, conditions or several calls. |
| The receiver accepts a simple JSON body. | You need authentication beyond a URL token, retries or transformations. |
Webhooks are fire-and-forget: a failed delivery is logged but not retried.