Skip to Content
FeaturesLifecycle Hooks

Lifecycle Hooks

Lifecycle hooks trigger operations automatically when content changes. When a record is created, updated, deleted, published, or unpublished, Foir can execute one or more operations in response.

Overview

Hooks connect content lifecycle events to operations. When an event fires on a model, Foir executes the configured operations with the record’s id and model key.

Page published -> Execute "notify-slack" operation (async) -> Execute "sync-cdn" operation (async) -> Execute "update-search-index" operation (sync)

Lifecycle Events

A project hook can subscribe to any project-plane event. Hook Events is the complete catalogue — every event, and the exact payload keys each one delivers.

Two families cover most hooks:

Record events — fired when content changes:

EventWhen It Fires
RECORD_CREATEDA new record is created
RECORD_UPDATEDA record is updated
RECORD_DELETEDA record is deleted
RECORD_PUBLISHEDA version is published (goes live)
RECORD_UNPUBLISHEDA published version is unpublished

Operation events — fired when an operation execution reaches a terminal state. Useful for chaining follow-up work (notify Slack when a long-running export finishes, retry a related job, reconcile external state, etc.):

EventWhen It Fires
OPERATION_COMPLETEDOperation finished successfully; payload carries executionId, operationKey, status, and the typed result.
OPERATION_FAILEDOperation finished with an error; payload includes the error {code, message, retryable}.
OPERATION_CANCELLEDOperation was cancelled (by someone in the console or by the extension itself) before completing.
OPERATION_TIMED_OUTAn async-callback operation didn’t call back within callbackTtlSeconds and the watchdog reaped it.

The catalogue has more project-plane families: imports, migrations and bulk jobs, organizations and join requests, and the user events. The four user events (USER_CREATED, USER_UPDATED, USER_DELETED, USER_MERGED) and SESSION_REVOKED are the ones to use to keep your own user store in step with Foir’s, or to drop a revoked session from a cache. USER_CREATED fires however somebody comes to exist: signing up, a first provider sign-in, being created or invited, SCIM, or a save that names them by an app’s identity. USER_DELETED carries who went and never their address, which the deletion erased.

Hook Configuration

Each hook specifies:

FieldDescription
eventThe event that fires the hook
operationKeyThe operation to execute
filterOptional. Each scalar value must equal the event payload key of the same name, for example { "modelKey": "blog-post" }. User, session and operation events carry a state snapshot; RECORD_* events carry none, only recordId and modelKey, so a hook cannot filter on a record’s fields
isActiveSet false to stop the hook firing without removing it

In the console

Configuring Hooks

  1. Go to Content > Models
  2. Select a model (e.g., “Blog Post”)
  3. Open the Hooks tab and click Create Hook. The hook editor opens with the model filled in
  4. Select the event (e.g., RECORD_PUBLISHED) and choose the operation to execute
  5. Save. A hook is its own definition, released like the rest of your drafts

You can also manage every hook from Automation > Hooks.

Creating an Operation for Hooks

Before adding a hook, you need an operation to target:

  1. Go to Automation > Operations
  2. Click New Operation
  3. Configure the key and endpoint URL
  4. Save

See Operations for the full guide.

Workspace Hooks

Everything above is a project hook: it subscribes to content events inside one project. A workspace hook sits a level up: it subscribes to membership, plan and project events across the whole workspace (the tenant and every project in it) and is configured under Workspace > Hooks in the platform console, not under a model.

Workspace Events

EventWhen It Fires
MEMBERSHIP_GRANTEDA member is added to the workspace, or given access to a project in it
MEMBERSHIP_REVOKEDA member’s access is withdrawn
INVITATION_ACCEPTEDAn invitation to the workspace is accepted
TENANT_PLAN_CHANGEDThe workspace moves to a different plan
TENANT_SUBSCRIPTION_STATUS_CHANGEDThe subscription status changes (e.g. past due, cancelled)
PROJECT_CREATEDA project is created in the workspace
PROJECT_ARCHIVEDA project is deleted
PROJECT_REACTIVATEDA deleted project is reactivated

See Hook Events for the payload each one delivers.

MEMBERSHIP_ROLE_CHANGED is in the event vocabulary but is never emitted. A role change is applied as a revoke followed by a grant, so it reaches you as MEMBERSHIP_REVOKED and then MEMBERSHIP_GRANTED for the same member. Subscribe to those two instead: a hook on MEMBERSHIP_ROLE_CHANGED is refused rather than accepted and left silent, and the console’s event picker does not offer it.

A workspace hook cannot subscribe to a project event, and a project hook cannot subscribe to a workspace event. The two vocabularies are disjoint, and a subscription on the wrong plane is refused rather than accepted and left silent.

What a Workspace Hook Can Do

TargetEffect
NotificationFoir raises an in-app notification to the workspace members you name, delivered on whichever channels each recipient has enabled for the notification’s category. Nothing to host.
A workspace hook notifies. That is the whole set. It ran an operation and staged an AI draft too, each acting inside the project a PROJECT_CREATED or PROJECT_ARCHIVED event carried, and both are gone.

They went for the same reason. A workspace hook is configured against a project that may not exist yet, so the only operation or model it could name was one defined above a project and inherited by every project under it. Definitions are not shared across projects any more — each belongs to exactly one — so there is nothing left for such a hook to name, and naming something that will not exist is not a configuration.

Project hooks are unaffected: they run operations and AI effects on their own project’s events, against their own project’s resources.

Notification Recipients

A project hook’s notification can address the triggering record’s owner or the project’s managers. A workspace event carries neither a record nor (usually) a project, so those strategies have nothing to resolve against: a workspace hook’s notification must name its recipients explicitly, and they must be workspace managers.

Sync or async is the operation’s setting, not the hook’s

A hook has no async field. It never had one. A hook references an operation by operationKey, and whether that work runs inline or on a queue is declared on the operation — supportsAsync, and the execution mode a run is dispatched with. See Defining Operations.

This matters when you are trying to make one hook behave differently from another on the same operation: you cannot. Two hooks pointing at one operation get that operation’s execution mode. If you need both behaviours, you need two operations.

The field a hook does have for turning it off is isActive.

Via the CLI

# List all hooks foir hooks list # Get a hook by key or ID foir hooks get <keyOrId> # Create a hook foir hooks create --data '{ "key": "notify-on-publish", "name": "Notify on Publish", "event": "RECORD_PUBLISHED", "filter": { "modelKey": "blog-post" }, "operationKey": "slack-notify-publish" }' # Update a hook foir hooks update <id> --data '{"isActive": false}' # Delete a hook foir hooks delete <id> # List recent deliveries for a hook (filter by status) foir hooks deliveries <hookId> --status failed --first 20 # Retry a failed delivery foir hooks retry-delivery <deliveryId> # Send a synthetic delivery to verify the receiver foir hooks test <hookId> --data '{"recordId": "rec_abc123"}'

See foir hooks for the full subcommand and option reference.

Via the API

Operations triggered by hooks receive a standardized payload. The event’s own keys arrive under input:

FieldDescription
executionIdThis dispatch’s execution ID. Key your handler on it so a retry is a no-op
operationKeyWhich operation is being called
trigger.typelifecycle
input.recordIdThe record ID, on record events
input.modelKeyThe model key
input.seqCommit-order position in the project’s stream, for last-write-wins. Absent on a foir hooks test fire
context.tenantIdWorkspace ID
context.projectIdProject ID
context.userIdThe owner of the event’s record, or the user a user event is about, when there is one
context.timestampWhen the operation was dispatched

A hook dispatch carries no record block and no field content. The payload identifies what changed; read the record back through the API under your own credentials when you need its data. That is deliberate — the event log is readable by anyone who can read events for the project, while a record is governed by ownership, grants, borrows and per-field read rules, so copying content into an event would move it out from under all of them.

Hook Events lists the exact keys each event delivers, Webhooks covers verification and ordering, and Operations has the full HTTP contract and response format.

Config System

Hooks can also be defined in foir.config.ts using defineHook. See the Configuration reference for details.

Common Patterns

Slack Notification on Publish

Create an operation that POSTs to a Slack webhook, then add it as a hook on the RECORD_PUBLISHED event:

{ "event": "RECORD_PUBLISHED", "operationKey": "slack-notify-publish" }

External System Sync

Keep an external system in sync by triggering on create, update, and delete. Create separate hooks for each event, all pointing to the same sync operation:

[ { "event": "RECORD_CREATED", "operationKey": "sync-to-external" }, { "event": "RECORD_UPDATED", "operationKey": "sync-to-external" }, { "event": "RECORD_DELETED", "operationKey": "delete-from-external" } ]

Conditional Webhook

Only notify for one model. A filter matches the event’s payload, so scope the hook to the model and check the record’s own fields (a market, say) in the operation after reading the record back:

{ "event": "RECORD_PUBLISHED", "operationKey": "notify-uk-team", "filter": { "modelKey": "article" } }

Best Practices

  • Use async for external calls — do not slow down content operations with network latency.
  • Add retry policies on operations — configure retries for resilience against transient failures.
  • Keep filters simple: simple hooks are easier to debug.
  • Monitor deliveries — check the hook deliveries list for failures.
  • Test with draft content — use foir hooks test to verify hooks work before going live.
  • Document hook purpose — use operation descriptions to explain why each hook exists.
Last updated on