Middesk webhooks: X-Middesk-Signature-256 verification, event
parsing, and webhook endpoint management.
Middesk signs each delivery with HMAC-SHA256 of the raw request body,
keyed by the secret you set on the webhook, and sends the lowercase
hex digest in X-Middesk-Signature-256. Only SHA-256 is supported
here (an older Middesk doc described a SHA-1 X-Middesk-Signature
header; the current docs don't).
No signed timestamp. The signature covers only the body, so a
captured delivery can be replayed. Record each event id once
(e.g. in a store) and ignore repeats; Middesk also retries
deliveries (up to 10 times over about 3 days), so dedupe is needed
anyway. Sandbox and production need separate webhook endpoints.
See https://docs.middesk.com/build/secure-webhooks.
Functions
construct-event
fn (request: Map): Map
fn (request: Map, secret: Str): Map
Verify a webhook request (see verify-request) and return the parsed
event (see parse-event), or an Err when the signature is invalid.
Example
middesk-webhook
meta {webhook: {service: "middesk", path: "/middesk/webhook"}, secret-headers: ["x-middesk-signature-256"]}
fn (request) {
event ::middesk::webhooks/construct-event(request)
cond {
is-err(event) => { ::hot::http/HttpResponse({status: 401, body: "invalid signature"}) }
=> {
// Dedupe on event.id; when event.type is "business.updated", fetch
// the business and summarize it for the reviewer agent.
::hot::http/HttpResponse({status: 200, body: {received: true}})
}
}
}
middesk.webhook.secret
create-webhook
fn (url: Str, enabled-events: Vec<Str>, opts: Map): Map
fn (url: Str, enabled-events: Vec<Str>, opts: Map, options: Map): Map
POST /webhooks - Register an endpoint. enabled-events lists event
types (["*"] for all), e.g. ["business.updated", "order.updated"].
opts.secret sets the signing secret: without one Middesk sends no
signature and verify-request can't pass, so always set it (store
the same value as middesk.webhook.secret). Other opts: include,
event_schemas and the oidc_* fields.
Example
secret ::hot::random/random-string(40)
::middesk::webhooks/create-webhook("https://myapp.hot.dev/middesk/webhook", ["business.updated"], {secret: secret})
delete-webhook
fn (webhook-id: Str): Any
fn (webhook-id: Str, options: Map): Any
DELETE /webhooks/{id} - Remove an endpoint.
Example
::middesk::webhooks/delete-webhook("whk_j1k2l3")
get-webhook
fn (webhook-id: Str): Map
fn (webhook-id: Str, options: Map): Map
GET /webhooks/{id} - Retrieve an endpoint (the secret is not returned).
Example
hook ::middesk::webhooks/get-webhook("whk_j1k2l3")
hook.enabled_events
list-webhooks
fn (): Map
fn (params: Map): Map
fn (params: Map, options: Map): Map
GET /webhooks - Your webhook endpoints. params: page, per_page.
Example
hooks ::middesk::webhooks/list-webhooks({per_page: 50})
map(hooks.data, %.url)
mark-webhook-secret
fn (params: Map): Map
Mask the signing secret in create-webhook or update-webhook params
in call records, and return the params unchanged. Exposed for testing.
Example
params ::middesk::webhooks/mark-webhook-secret({secret: ::hot::ctx/get("middesk.webhook.secret")})
::middesk::webhooks/update-webhook("whk_j1k2l3", params)
parse-event
fn (body: Any): Map
Flatten a webhook body into {id, type, created-at, account-id, object-type, object-id, object}. type is e.g. "business.updated"
or "order.updated"; object is data.object (for business events,
the business with its status). Dedupe on id.
Example
event ::middesk::webhooks/parse-event({
id: "evt_1",
type: "business.updated",
data: {object: {object: "business", id: "biz_1", status: "in_review"}}
})
event.type // "business.updated"
event.object-id // "biz_1"
event.object.status // "in_review"
update-webhook
fn (webhook-id: Str, params: Map): Map
fn (webhook-id: Str, params: Map, options: Map): Map
PUT /webhooks/{id} - Update url, secret, enabled_events or
disabled_at (a timestamp pauses deliveries).
Example
// Pause deliveries
::middesk::webhooks/update-webhook("whk_j1k2l3", {disabled_at: "2026-11-09T00:00:00Z"})
verify-request
fn (request: Map): Bool
fn (request: Map, secret: Str): Bool
Verify an inbound Middesk webhook over ::hot::http/raw-body. Uses
middesk.webhook.secret by default and fails when it is unset; an
empty explicit secret never verifies. There is no timestamp to check:
dedupe on the event id (see the namespace doc).
Example
middesk-webhook
meta {webhook: {service: "middesk", path: "/middesk/webhook"}, secret-headers: ["x-middesk-signature-256"]}
fn (request) {
if(not(::middesk::webhooks/verify-request(request)),
::hot::http/HttpResponse({status: 401, body: "invalid signature"}),
::hot::http/HttpResponse({status: 200, body: {received: true}}))
}
middesk.webhook.secret
verify-signature
fn (signature: Str, raw-body: Str | Bytes, secret: Str): Bool
Verify an X-Middesk-Signature-256 value against a raw body: lowercase
hex HMAC-SHA256 of the body with secret, compared in constant time.
Fails closed on an empty secret or signature. Exposed for testing;
verify-request reads them from the request.
Example
body "{\"id\":\"evt_1\",\"type\":\"business.updated\"}"
signature "5ee3d4a621ede3053cda09d5..."
::middesk::webhooks/verify-signature(signature, body, ::hot::ctx/get("middesk.webhook.secret"))