Receive deliveries and verify signatures
Your application receives work from the platform as HTTP POSTs: deliveries of
dispatch jobs (events matched by your subscriptions, and direct jobs) and
scheduled-job firings. This page builds a receiver that checks every
request really came from the platform, processes it once, and answers so the platform does the right
thing next. Delivery is the full description of the request and the answers.
What arrives
Section titled “What arrives”A POST to the target URL with:
- a body: the JSON envelope (
id,type,attemptNumber,time,source,subject,messageGroup,correlationId,clientId,clientCode,data), or the raw payload when the subscription or job is data-only; X-Dispatch-Job-IdandX-Event-Type(the job id and code);X-FlowCatalyst-Client: {clientId}:{clientCode}when the job belongs to a client;X-FlowCatalyst-TimestampandX-FlowCatalyst-Signature, andAuthorization: Bearer <token>, when the signing service account has those credentials.
1. Get the secret
Section titled “1. Get the secret”Deliveries are signed with a service account’s signing secret: the account of the
subscription’s connection, or for application-owned connections and scheduled-job firings, your
application’s own service account (see who signs a delivery).
The secret is never shown after it is created. To get a value you can configure, open the service
account in the console (Service accounts) and choose Regenerate Secret under Signing Secret
(HMAC-SHA256), or call POST /api/service-accounts/{id}/regenerate-signing-secret. Store it in your
secret manager and expose it to the receiver, conventionally as FLOWCATALYST_SIGNING_SECRET.
2. Verify, then parse
Section titled “2. Verify, then parse”The signature is hex(HMAC-SHA256(secret, timestamp + rawBody)). Verify over the exact bytes you
received, before any JSON parsing: re-serialised JSON has different bytes. The SDK verifiers also
refuse a timestamp older than 5 minutes (a replay guard) or too far in the future, compare in
constant time, and fail closed when the secret is empty.
verifier := webhook.NewVerifier(os.Getenv("FLOWCATALYST_SIGNING_SECRET"))
func handle(w http.ResponseWriter, r *http.Request) { body, err := io.ReadAll(r.Body) if err != nil { http.Error(w, "read body", http.StatusBadRequest) return } if err := verifier.Verify(body, r.Header.Get(webhook.SignatureHeader), r.Header.Get(webhook.TimestampHeader)); err != nil { http.Error(w, "invalid signature", http.StatusUnauthorized) return } var env struct { ID string `json:"id"` Type string `json:"type"` Data json.RawMessage `json:"data"` } _ = json.Unmarshal(body, &env) // ... process, keyed on env.ID ... w.WriteHeader(http.StatusOK)}webhook.Validator (ValidatorFromEnv, Validate(sig, ts, body)) is the same check with
sentinel errors for each failure; prefer Verifier in new code.
import io.flowcatalyst.sdk.webhook.WebhookSignature;
try { WebhookSignature.verify(rawBodyBytes, request.header("X-FlowCatalyst-Signature"), request.header("X-FlowCatalyst-Timestamp"), signingSecret);} catch (WebhookSignature.WebhookSignatureException e) { return response(401);}JsonNode envelope = mapper.readTree(rawBodyBytes);import { verifyDeliverySignature, WebhookSignatureError } from "@flowcatalyst/sdk";
try { verifyDeliverySignature({ rawBody, // string or Uint8Array: the body exactly as received signature: req.headers["x-flowcatalyst-signature"], timestamp: req.headers["x-flowcatalyst-timestamp"], secret: process.env.FLOWCATALYST_SIGNING_SECRET!, });} catch (e) { if (e instanceof WebhookSignatureError) return reply.code(401).send({ error: e.code }); throw e;}const envelope = JSON.parse(rawBody.toString());Most frameworks parse JSON before your handler runs; configure the route to keep the raw body.
// routes/api.php: the middleware verifies with FLOWCATALYST_SIGNING_SECRETRoute::post('/webhooks/orders', OrderWebhookController::class) ->middleware('flowcatalyst.webhook');Or by hand:
use FlowCatalyst\Exceptions\WebhookValidationException;use FlowCatalyst\Webhook\WebhookValidator;
try { WebhookValidator::fromConfig()->validateRequest($request);} catch (WebhookValidationException $e) { return response()->json(['error' => 'Invalid signature'], 401);}Keep the route out of middleware groups that rewrite the body.
use flowcatalyst_sdk::webhook::{WebhookVerifier, SIGNATURE_HEADER, TIMESTAMP_HEADER};
let verifier = WebhookVerifier::from_env()?; // FLOWCATALYST_SIGNING_SECRETlet signature = headers.get(SIGNATURE_HEADER).and_then(|v| v.to_str().ok());let timestamp = headers.get(TIMESTAMP_HEADER).and_then(|v| v.to_str().ok());verifier.verify(&raw_body, signature, timestamp)?;The bearer token is optional extra. The Authorization: Bearer header carries the service
account’s auth token, a static credential. Some verifiers can require it as a second gate
(expectedBearerToken in TypeScript, with_bearer_token in Rust, FLOWCATALYST_WEBHOOK_AUTH_TOKEN
in Laravel). It is never a substitute for the signature, which binds the secret to this body at this
time.
3. Process once
Section titled “3. Process once”Delivery is at least once: a timeout, a lost answer or an operator’s requeue can bring the same
job again. Make the handler idempotent with the job id (X-Dispatch-Job-Id, or id in the
envelope), for example a unique key on a “processed deliveries” table written in the same
transaction as the work. Within a message group the platform delivers in order, so you can rely on
seeing an aggregate’s events in sequence (see ordering).
4. Answer
Section titled “4. Answer”| Answer | Effect on the job |
|---|---|
2xx |
Done: COMPLETED. |
2xx with {"ack": false, "notBefore": "<RFC 3339>", "delaySeconds": n} |
Deferred: back to waiting, delivered again at notBefore (else after delaySeconds, else 30 seconds). No attempt is used. Send both fields. |
429, with Retry-After |
Deferred for that long (30 seconds without the header). No attempt is used. |
401 or 403 |
Failed at once: retrying with the same credentials cannot help. |
422 with the header FlowCatalyst-Outcome: reject |
Failed at once: “this will never work”. |
5xx, another 4xx, a timeout, a connection error |
A failed attempt; retried with backoff until its attempts run out, then FAILED. |
Use ack: false when you are healthy but cannot take this one yet: a record it depends on has
not arrived, a downstream system is in maintenance, you are throttling yourself. It is not counted as
a failure. Deferrals are not capped, so in a BLOCK_ON_ERROR subscription an endless deferral holds
the group.
w.Header().Set("Content-Type", "application/json")later := time.Now().Add(2 * time.Minute).UTC()_ = json.NewEncoder(w).Encode(map[string]any{ "ack": false, "notBefore": later.Format(time.RFC3339), "delaySeconds": 120,})const notBefore = new Date(Date.now() + 120_000).toISOString();reply.code(200).send({ ack: false, notBefore, delaySeconds: 120 });return response()->json([ 'ack' => false, 'notBefore' => now()->addMinutes(2)->toIso8601ZuluString(), 'delaySeconds' => 120,]);use flowcatalyst_sdk::webhook::MediationResponse;
// {"ack":false,"delaySeconds":120}; it has no notBefore field yetlet answer = serde_json::to_string(&MediationResponse::defer(120))?;Keep the handler fast. A delivery waits at most the job’s timeout (30 seconds by default, never more than 2 minutes); answer once the work is safely recorded, and do long work in the background.
Multi-tenant receivers
Section titled “Multi-tenant receivers”A job that belongs to a client carries X-FlowCatalyst-Client: {clientId}:{clientCode} (and
clientId / clientCode in the envelope). Route the work to that tenant with it, after the
signature check. The Rust SDK parses it with parse_client_header. clientCode is left out when
the client cannot be resolved.
Data-only bodies
Section titled “Data-only bodies”A subscription or job with dataOnly: true sends the payload byte for byte with its own
Content-Type (XML stays XML), and the identifying fields travel only in the headers. Verification is
identical: the signature covers whatever bytes were sent. Use data-only when the receiver expects a
fixed format that is not FlowCatalyst’s envelope.
Test it locally
Section titled “Test it locally”Sign a body yourself with the same secret and post it:
ts=$(date -u +%Y-%m-%dT%H:%M:%S.000Z)body='{"id":"test1","type":"orders:sales:order:placed","data":{"orderId":"ord_1"}}'sig=$(printf '%s%s' "$ts" "$body" | openssl dgst -sha256 -hmac "$FLOWCATALYST_SIGNING_SECRET" -hex | awk '{print $NF}')curl -i -X POST http://localhost:3000/webhooks/orders \ -H "Content-Type: application/json" \ -H "X-FlowCatalyst-Timestamp: $ts" -H "X-FlowCatalyst-Signature: $sig" \ -d "$body"Laravel has a command that checks a captured delivery against the configured secret:
php artisan flowcatalyst:verify-signature --timestamp=... --signature=... --body-file=body.json.
With fcdev, a subscription may target localhost; a deployed platform refuses loopback and private
targets by default.
Rotate the secret
Section titled “Rotate the secret”Regenerating a signing secret replaces it immediately: deliveries from that moment are signed with
the new secret, and a receiver still holding the old one answers 401, which fails those jobs at
once. Rotate in a quiet moment, update the receiver straight away, then requeue anything that failed
in between from the console’s Dispatch jobs page.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Cause |
|---|---|
Every delivery fails 401 with a signature error |
The receiver has another account’s secret, an old one, or verifies a re-serialised body. |
timestamp expired |
The receiver’s clock is wrong, or you are replaying an old captured request. |
| Deliveries arrive without signature headers | The signing account has no credentials, or none could be resolved; the attempt in the console records why. Fix the account rather than accepting unsigned requests. |
| The same job arrives twice | Expected under at-least-once delivery; deduplicate on the job id. |
Related
Section titled “Related”- Delivery: envelopes, signatures and acknowledgement.
- Delivery and webhook signatures: the exact signing string and test vectors.
- Subscriptions and connections.
- Framework receivers: Receivers.
- Decisions: sign the received bytes, ack=false means deferral.