Skip to main content
API-Defined Hooks let you automate actions in response to events, on a schedule, or on demand — all configured through the REST API or Admin UI without writing backend code.
This page covers API-Defined Hooks — hooks managed via the REST API with event, schedule, and manual triggers. For the code-level Python hook system used to extend SnackBase internals, see the Hook System Reference.

Overview

An API-defined hook consists of three parts:
  1. Trigger — When the hook fires (event, schedule, or manual)
  2. Condition — An optional rule expression that gates execution
  3. Actions — An ordered list of operations to perform

Key Features

  • Three Trigger Types: Event-driven, cron-scheduled, or manual
  • Conditional Execution: Gate hooks with rule expressions
  • Action Pipelines: Chain multiple actions in sequence
  • Execution Logging: Full history with status, duration, and errors
  • Enable/Disable Toggle: Pause hooks without deleting them

Trigger Types

Event Triggers

Fire when a specific event occurs in your application:
{
  "type": "event",
  "event": "records.create",
  "collection": "orders"
}
Supported events:
EventFires When
records.createA record is created
records.updateA record is updated
records.deleteA record is deleted
auth.loginA user logs in
auth.registerA new user registers
The collection field is optional — omit it to match events across all collections.

Schedule Triggers

Fire on a cron schedule:
{
  "type": "schedule",
  "cron": "0 9 * * MON"
}
Standard 5-field cron syntax is supported:
┌───────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌───────────── day of month (1-31)
│ │ │ ┌───────────── month (1-12)
│ │ │ │ ┌───────────── day of week (0-6, 0=Sunday)
│ │ │ │ │
* * * * *
When a scheduled hook is enabled, next_run_at is automatically calculated. Disabling clears it; re-enabling recalculates it.

Manual Triggers

Fire only when explicitly triggered via the API:
{
  "type": "manual"
}
Trigger manually:
curl -X POST https://api.snackbase.dev/api/v1/hooks/{hook_id}/trigger \
  -H "Authorization: Bearer {token}"

Condition Expressions

Add an optional condition to gate hook execution. The hook only fires if the expression evaluates to true:
{
  "trigger": { "type": "event", "event": "records.create", "collection": "orders" },
  "condition": "total >= 100"
}
Conditions use the same rule expression syntax as collection rules and webhook filters.
If a condition expression fails to evaluate, the hook fires anyway (fail-open design).

Actions

Actions are executed sequentially. If an action fails, execution stops and the hook is logged with partial status.

Supported Action Types

Action TypeDescription
send_webhookSend an HTTP request to an external URL
send_emailSend an email (via configured email provider)
create_recordCreate a record in a collection
update_recordUpdate an existing record
delete_recordDelete a record
enqueue_jobEnqueue a background job

Template Variables

Action configurations support template variables that resolve at execution time:
VariableDescription
{{record.field}}Field value from the triggering record
{{auth.user_id}}User ID from the execution context
{{auth.email}}User email from the execution context
{{now}}Current UTC timestamp (ISO 8601)
Example — send a webhook when a high-value order is created:
{
  "name": "Notify on large orders",
  "trigger": {
    "type": "event",
    "event": "records.create",
    "collection": "orders"
  },
  "condition": "total >= 500",
  "actions": [
    {
      "type": "send_webhook",
      "config": {
        "url": "https://slack.example.com/webhook",
        "body_template": {
          "text": "New order #{{record.id}} for ${{record.total}} from {{record.customer_name}}"
        }
      }
    }
  ]
}

Execution Logging

Every hook execution is logged with:
FieldDescription
trigger_typeevent, schedule, or manual
statussuccess, failed, or partial
actions_executedNumber of actions completed
error_messageError details (if failed/partial)
duration_msExecution time in milliseconds
execution_contextSnapshot of triggering context (event, account, record, collection)
executed_atTimestamp

Execution Statuses

StatusMeaning
successAll actions executed without error
failedCondition not met or first action failed
partialSome actions completed before a failure

Limits

LimitDefault
Max hooks per account50 (configurable)
Max action execution depth5 (prevents recursive loops)

Comparison: Hooks vs Webhooks vs Workflows

FeatureAPI-Defined HooksOutbound WebhooksWorkflows
Trigger typesEvent, schedule, manualRecord events onlyEvent, schedule, manual, webhook
ActionsMultiple, sequencedSingle HTTP POSTMulti-step with branching
ConditionsRule expressionsFilter expressionsPer-step conditions
Delays/WaitsNoNoYes (wait_delay, wait_condition)
BranchingNoNoYes (condition steps)
Parallel executionNoNoYes (parallel steps)
Best forSimple automationsExternal notificationsComplex multi-step processes