Appearance
Automations
22 operations. Paths are relative to https://api.frege.io.
List this environment's hooks
GET/v1/projects/{id}/hooks
Each with its newest run, which is the quickest answer to "is this working". A hook runs from a queue after its event, so a failure never reaches whoever caused the event — the runs are the only report of it.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 404 | Not Found | error envelope |
Create a hook
POST/v1/projects/{id}/hooks
A hook is: WHEN (trigger — tool_call, the default, runs after any of its tools is called, up to 20 of them; sign_in, credential_renewed and credential_expired run on what happens to a customer; schedule runs on the hook's own schedule {cron, time_zone}: five cron fields in an IANA time zone, UTC when none is named — a wall-clock time the clocks skip fires when they jump, one they repeat fires once, and times missed while nothing ran fire once; GET /projects/{id}/hooks shows next_fire_at), ON (tool_call only: success — the default, failure or any), IF (an optional filter, every condition must hold) and THEN (steps run in order). delay_seconds (up to 604800, seven days; not on a schedule hook) starts each run that long after its event, the filter read when the event arrives. The filter and every {{event.…}} reference may use only fields all the hook's tools carry — see GET /projects/{id}/hooks/tools; {{event.tool}} says which one was called. client.* is there only when a customer made the call, so a hook that acts as the customer should filter on client.id exists. Each step has an id, a type and params; any string in params may reference the call ({{event.response.id}}) or an EARLIER step's output ({{steps.me.user.phone}}). A reference that finds nothing is empty, never an error: inside text it writes nothing, standing alone as a value it leaves that key out, and the step's summary lists it under empty. An object or list inside text is written as JSON. Everything checkable is checked here: the tools, the fields, step ids, step types, every reference, and each step's own params — a call_tool must name one of this environment's tools, and one that changes something upstream needs allow_writes. Calls made by hooks, the playground and evals never start a hook. Step types: call_tool {tool, arguments} calls a tool as the customer; update_client {identifier, identities} records who they are — identifier replaces what the Clients list shows them as; identities is a map of any keys (phone, email, username, name, client_id, …) merged into the customer's identities, each key replacing the value it had, subject excepted since it is not recorded there; none of these need be unique; webhook {url, method, headers, body} sends signed JSON (see the secret endpoint) — method is GET, POST, PUT, PATCH or DELETE, POST when left out; notify {channel: email|telegram, to: [up to 20 recipients], subject, text} tells project members or chats through the environment's bot, each in a message of their own; to is written out, never a reference, and a single string is read as a list of one. Problems with one recipient come back at steps.N.params.to.M. The step fails only when no recipient was reached; those that were not are listed under failed in its summary. run_agent {agent, prompt, customer, deliver, conversation, tools} runs one of this environment's agents for a customer as a proactive run — recorded with trigger hook or schedule, with that agent's guardrails, write policy and usage like any run — and delivers its reply: agent is the agent's id; prompt is what it is asked, references filled in; customer is one {{event.…}} reference standing alone or a customer's id, {{event.client.id}} when left out; deliver is reply_channel (the default; Telegram, the one channel for now), telegram or none; conversation is latest (the default: the customer's newest conversation with the agent, else a new one) or new. tools are the tools the run may call, by name, written out (at most 50): a proactive run is denied every other tool, and with none it calls no tool at all (ADR-0030). The step finishes when the reply is handed to the channel (delivery.status requested, with its request_id); the channel tells what came of it in its own events, telegram.customer_message.sent or .failed (no_bot, no_chat, blocked, muted, capped, refused, error), carrying that request id: a customer with no chat with the bot, or who blocked it, is sent nothing. A reply the channel did not take fails the step and is not retried, as the run is kept. Its output is {run_id, text, session_id, delivery: {channel, status, request_id}}. A test does not run it. A webhook hook (trigger webhook) names its source, the id of one of GET /projects/{id}/hooks/sources, and runs on each verified delivery to it; its filter and references read event.body.* and event.headers.*. customer {from, identity} names who the delivery is about: from is a path under event.body or event.headers, identity the identity it is (phone, email or any other but subject); when a run starts the value, normalized, is matched exactly against the customers' identities: one customer, and client.* is theirs for every step; none or several, and every step is skipped with the reason, the run succeeding. Its run_agent never writes event.body or event.headers into the prompt: the delivery, redacted by the environment's redaction, follows the prompt as data, never as instructions. On telegram, notify's to may name customer: the customer the event is about, in their chat with the bot; telegram tells what came of it, as for run_agent's reply. Such a notify may name its topic (lowercase letters, digits, _ and -, up to 40, such as orders): the customer gets a button under it that stops that topic's alerts, /stop stops every alert and /alerts lets them all through again; one stopped is not sent and fails with the reason muted, and one over the bot's daily_customer_cap with the reason capped.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
Request body (application/json)
Schema: api.hookRequest.
| Field | Type | Description |
|---|---|---|
allow_writes | boolean | |
condition | object | Condition is an expression over event and now (GET /hooks/expressions), held together with filter; absent or null holds always. |
customer | hooks.CustomerMatch | |
delay_seconds | integer | DelaySeconds is how long after its event a run starts, up to seven days; 0, at once. |
enabled | boolean | |
filter | hooks.Condition[] | |
max_attempts | integer | |
name | string | |
on | string | |
schedule | hooks.Schedule | |
source | string | Source is a webhook hook's: the id of the source whose deliveries start it. |
steps | hooks.Step[] | |
tools | string[] | |
trigger | string |
Responses
| Status | Description | Body |
|---|---|---|
| 201 | Created | data |
| 404 | Not Found | error envelope |
| 422 | Unprocessable Entity | error envelope |
One hook
GET/v1/projects/{id}/hooks/{hookID}
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
hookID (required) | path | string | Hook ID |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 404 | Not Found | error envelope |
Replace a hook
PUT/v1/projects/{id}/hooks/{hookID}
Same body and checks as creating one. Runs already queued run the new definition.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
hookID (required) | path | string | Hook ID |
Request body (application/json)
Schema: api.hookRequest.
| Field | Type | Description |
|---|---|---|
allow_writes | boolean | |
condition | object | Condition is an expression over event and now (GET /hooks/expressions), held together with filter; absent or null holds always. |
customer | hooks.CustomerMatch | |
delay_seconds | integer | DelaySeconds is how long after its event a run starts, up to seven days; 0, at once. |
enabled | boolean | |
filter | hooks.Condition[] | |
max_attempts | integer | |
name | string | |
on | string | |
schedule | hooks.Schedule | |
source | string | Source is a webhook hook's: the id of the source whose deliveries start it. |
steps | hooks.Step[] | |
tools | string[] | |
trigger | string |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 404 | Not Found | error envelope |
| 422 | Unprocessable Entity | error envelope |
Delete a hook
DELETE/v1/projects/{id}/hooks/{hookID}
Removes the hook and its run history. To stop it while keeping both, update it with enabled false.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
hookID (required) | path | string | Hook ID |
Responses
| Status | Description | Body |
|---|---|---|
| 204 | No Content | |
| 404 | Not Found | error envelope |
A hook's runs, newest first
GET/v1/projects/{id}/hooks/{hookID}/runs
One run per event the hook applied to, kept for 30 days. A failed run that may pass (a timeout, a 5xx) is retried with backoff up to max_attempts; next_attempt_at says when. A retry resumes at the step that failed: the steps that succeeded are not run again, and their outputs stay in scope for {{steps.<id>.…}}.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
hookID (required) | path | string | Hook ID |
page | query | integer | Page, from 1 |
page_size | query | integer | Page size, at most 100 |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 404 | Not Found | error envelope |
Run a failed run again
POST/v1/projects/{id}/hooks/{hookID}/runs/{runID}/retry
Queues a FAILED run for one more attempt, now, with the hook's current definition. A succeeded run is not repeated: it may have written something. The attempt resumes where the run stopped: the steps it already finished (succeeded or skipped) are not run again — each keeps its report, and a succeeded one's recorded output is what later steps reference — as long as the hook's steps still begin with them, by id and type, in order. It starts at the first step not finished; to run a finished step again, give it another id.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
hookID (required) | path | string | Hook ID |
runID (required) | path | string | Run ID |
Responses
| Status | Description | Body |
|---|---|---|
| 204 | No Content | |
| 404 | Not Found | error envelope |
A hook's signing secret
GET/v1/projects/{id}/hooks/{hookID}/secret
What a webhook receiver verifies deliveries with: X-Frege-Signature is sha256=<hex HMAC-SHA256(secret, "<X-Frege-Timestamp>.<body>")>. Each delivery also carries the Standard Webhooks headers (standardwebhooks.com): webhook-id, the step's delivery key <run id>:<step id> (also X-Frege-Delivery-Step), the same on every attempt and different for each webhook step of a run; webhook-timestamp, unix seconds; webhook-signature, v1,<base64 HMAC-SHA256(key, "<webhook-id>.<webhook-timestamp>.<body>")>, where the key is the secret's own bytes, whsec_ included, not base64-decoded: verify with a library's raw-key form (NewWebhookRaw in Go). Manager only — anyone holding it can forge a delivery.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
hookID (required) | path | string | Hook ID |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 404 | Not Found | error envelope |
Replace a hook's signing secret
POST/v1/projects/{id}/hooks/{hookID}/secret
Deliveries are signed with the new secret from now on; a receiver still verifying with the old one refuses them until it is updated.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
hookID (required) | path | string | Hook ID |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 404 | Not Found | error envelope |
What a hook's condition is written with
GET/v1/projects/{id}/hooks/expressions
A hook's condition is an expression (docs/reference/expr.md), held together with its filter: {"all": [c, ...]}, {"any": [c, ...]}, {"not": c}, or a comparison {"field": "event.client.email", "op": "matches", "value": "@example\.com$"} or {"left": v, "op": "...", "right": v}. operators lists every op and what its right side takes; kinds the kinds of value (literal, ref, template); roots what a path starts with: event, the event's fields as GET /hooks/triggers lists them, and now, when the event happened. A path the chosen events do not declare is refused when the hook is saved, with the JSON Pointer of the problem under condition.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 404 | Not Found | error envelope |
This environment's webhook sources
GET/v1/projects/{id}/hooks/sources
A source is a URL at Frege a legacy system sends its own webhooks to; each verified delivery starts the hooks whose trigger is webhook and whose source it is. The secret is never shown here.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 404 | Not Found | error envelope |
Create a webhook source
POST/v1/projects/{id}/hooks/sources
name; verification {mode, header, prefix, encoding, timestamp_header, tolerance_seconds}: mode hmac — HMAC-SHA256 with the secret over the raw body, read from header after prefix (such as sha256=), encoding hex (the default) or base64; with timestamp_header (unix seconds) the signed content is "<timestamp>.<body>" and a timestamp more than tolerance_seconds (300 by default, at most 3600) from now is refused. SHA-1 is not offered. Mode secret_header — the secret itself in header, after prefix (such as "Bearer "). delivery_id_header names the header carrying the sender's own delivery id: a delivery with an id the source already took is not taken again. secret, 16 to 512 characters, is for a sender that mints its own; without it Frege mints one. The answer carries receive_url, to give the sender, and the secret: the only time it is shown, but a rotation.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
Request body (application/json)
Schema: api.hookSourceRequest.
| Field | Type | Description |
|---|---|---|
delivery_id_header | string | DeliveryIDHeader carries the sender's own delivery id, which dedupes. |
enabled | boolean | |
name | string | |
secret | string | Secret is the sender's own, at creation only; without it Frege mints one. |
verification | hooks.Verification |
Responses
| Status | Description | Body |
|---|---|---|
| 201 | Created | data |
| 403 | Forbidden | error envelope |
| 404 | Not Found | error envelope |
| 422 | Unprocessable Entity | error envelope |
One webhook source
GET/v1/projects/{id}/hooks/sources/{sourceID}
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
sourceID (required) | path | string | Source ID |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 404 | Not Found | error envelope |
Replace a webhook source
PUT/v1/projects/{id}/hooks/sources/{sourceID}
Same body as creating one, without secret (rotate it instead). The URL stays.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
sourceID (required) | path | string | Source ID |
Request body (application/json)
Schema: api.hookSourceRequest.
| Field | Type | Description |
|---|---|---|
delivery_id_header | string | DeliveryIDHeader carries the sender's own delivery id, which dedupes. |
enabled | boolean | |
name | string | |
secret | string | Secret is the sender's own, at creation only; without it Frege mints one. |
verification | hooks.Verification |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 403 | Forbidden | error envelope |
| 404 | Not Found | error envelope |
| 422 | Unprocessable Entity | error envelope |
Delete a webhook source
DELETE/v1/projects/{id}/hooks/sources/{sourceID}
Removes the source and its deliveries; its URL answers 404 from now on. A hook bound to it stays, and never runs again.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
sourceID (required) | path | string | Source ID |
Responses
| Status | Description | Body |
|---|---|---|
| 204 | No Content | |
| 403 | Forbidden | error envelope |
| 404 | Not Found | error envelope |
A webhook source's deliveries, newest first
GET/v1/projects/{id}/hooks/sources/{sourceID}/deliveries
Kept for 30 days, like hook runs. verified false is a refusal (error says why; the body is not kept); outcome is queued (its hooks were given it: runs lists each, with its status), no_hook (no enabled hook listened) or refused. customers are those its hooks matched.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
sourceID (required) | path | string | Source ID |
page | query | integer | Page, from 1 |
page_size | query | integer | Page size, at most 100 |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 404 | Not Found | error envelope |
Give a delivery to the source's hooks again
POST/v1/projects/{id}/hooks/sources/{sourceID}/deliveries/{deliveryID}/replay
A verified delivery, as it was kept (body, headers, received_at), becomes a new hook event: the hooks that listen now run on it, filters read again. A refused one kept no body (409).
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
sourceID (required) | path | string | Source ID |
deliveryID (required) | path | string | Delivery ID |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 403 | Forbidden | error envelope |
| 404 | Not Found | error envelope |
| 409 | Conflict | error envelope |
Replace a webhook source's secret
POST/v1/projects/{id}/hooks/sources/{sourceID}/secret
From now on deliveries verify with the new secret only; the sender must be given it, and until then its deliveries are refused (and kept as refused). The body may carry secret, for a sender that mints its own; without it Frege mints one. The answer is the only time it is shown.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
sourceID (required) | path | string | Source ID |
Request body (application/json)
Schema: api.hookSourceSecretRequest.
| Field | Type | Description |
|---|---|---|
secret | string |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 403 | Forbidden | error envelope |
| 404 | Not Found | error envelope |
| 422 | Unprocessable Entity | error envelope |
Try a hook without saving it
POST/v1/projects/{id}/hooks/test
Runs the hook in the body — not a stored one — on a made-up call, and reports what each step did. test_tool picks which of the hook's tools was called, the first one by default. client_id names the customer. data fills in the call: succeeded, status, args, response — tool, door, succeeded and status are filled in when left out; for credential_expired it is {reason}. It is checked against the tool's fields like a real call. matched says whether on and the filter let this call through; the steps run either way. Nothing is written: tools that change something upstream are skipped, and update_client reports what it WOULD record. Reads are real: they spend the customer's credential and each step's output is their account data, which is why this is organization-admin only.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
Request body (application/json)
Schema: api.testHookRequest.
| Field | Type | Description |
|---|---|---|
allow_writes | boolean | |
client_id | integer | |
condition | object | Condition is an expression over event and now (GET /hooks/expressions), held together with filter; absent or null holds always. |
customer | hooks.CustomerMatch | |
data | object (map) | |
delay_seconds | integer | DelaySeconds is how long after its event a run starts, up to seven days; 0, at once. |
enabled | boolean | |
filter | hooks.Condition[] | |
max_attempts | integer | |
name | string | |
on | string | |
schedule | hooks.Schedule | |
source | string | Source is a webhook hook's: the id of the source whose deliveries start it. |
steps | hooks.Step[] | |
test_tool | string | |
tools | string[] | |
trigger | string |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 403 | Forbidden | error envelope |
| 404 | Not Found | error envelope |
| 422 | Unprocessable Entity | error envelope |
The tools a hook may call on this environment
GET/v1/projects/{id}/hooks/tools
This environment's own tools, including intent tools. triggerable marks a tool a tool_call hook may run on, and fields lists what its calls carry: client.*, tool, door, succeeded, status, error, args.* from its parameters and body, response.* from what it answers — type any where the spec has no schema, so any path below it may be used. Intent tools are not triggerable: the calls they make are. mutating marks a tool that changes something upstream: a hook may call one only with allow_writes on, and only while the environment's write policy is "allow" — a hook runs unattended, so under "ask" there is nobody to ask.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 404 | Not Found | error envelope |
What a hook can run on
GET/v1/projects/{id}/hooks/triggers
tool_call — after one of the hook's tools is called; the tools and the fields each one carries come from GET /projects/{id}/hooks/tools. sign_in, credential_renewed and credential_expired — things that happen to a customer, each with what Frege knows of them: client.phone, email, username, subject and client.identities.* (what sign-ins and update_client recorded); credential_expired also names the renewal step the upstream refused and its status (upstream.step, upstream.status); sign_in and credential_renewed also carry upstream.<step>.* — what the upstream answered to each call step of this environment's sign-in or renewal recipe, typed from the spec, with every token and captured value the recipe reads removed and the environment's redaction applied. schedule — the hook's own schedule fired, with hook.id, hook.name and schedule.fired_for, local_time, cron and time_zone; it is about no customer, so its run_agent names one. Each names the fields a hook's filter and {{event.…}} references may use; for tool_call these are only the ones every tool has, each tool adds its own args.* and response.*. webhook — a verified delivery to one of this environment's webhook sources, with source.id, source.name, delivery.id, delivery.sender_id, body (JSON as parsed, else the text), headers (lower-case, never a secret) and received_at; a hook naming its customer also has client.*.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 404 | Not Found | error envelope |
Receive a webhook (a legacy system's)
POST/v1/webhooks/in/{sourceID}
Public: the system that sends the source's webhooks calls it, with no Frege sign-in. The delivery is verified as the source says — hmac: HMAC-SHA256 of the raw body (of "<timestamp>.<body>" with a timestamp header, which must be within the tolerance of now), in a named header after an optional prefix, hex or base64; secret_header: the secret itself in a named header after an optional prefix — and answered 202 with no body at once; the source's hooks run from a queue afterwards. A delivery whose sender id (delivery_id_header) the source already took is 202 and changes nothing. An unknown or turned-off source, and a delivery that fails verification, are all 404, alike. At most 64 KiB (413), and 20 a second per source, bursts of 100 (429).
Authentication: none.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
sourceID (required) | path | string | The source's public id, from its receive_url |
Request body (application/json)
Type: object.
Responses
| Status | Description | Body |
|---|---|---|
| 202 | Accepted | |
| 404 | Not Found | error envelope |
| 413 | Request Entity Too Large | error envelope |
| 429 | Too Many Requests | error envelope |