Skip to main content

Webhook deployments

A webhook deployment runs a tagged version of an Unstract Flow workflow each time another system sends it a request. The request can carry values for the run, such as an order number or a file name. You create one with the Webhook (HTTP) trigger type; Deployments covers the other fields.

Save the key​

When you create the deployment, Flow shows its Webhook API Key once: "Save this API key now. You won't be able to see it again." Store it where your system can read it, then select I've saved the key.

The deployment's page has a Webhook tab with the Webhook URL, the start of the key under API Key Prefix, and the header to send it in. Regenerate API Key replaces the key, and the old one stops working. A Viewer doesn't see it.

Start a run​

Send a POST request to the Webhook URL, with the key in the X-Webhook-Key header and the run's values under variables. Values outside variables are ignored, and the run still starts. Each request starts a new run, even when one for the same values is still running, until the deployment reaches its Parallelism.

To resend a request safely, send an Idempotency-Key header with a value of your own, such as an order number, of 1 to 255 characters. If the request times out, send it again with the same key and the same body: within 24 hours, Flow returns the run the first request started, with the header Idempotent-Replayed: true, and starts nothing. A key belongs to its deployment. Without the header, a repeated request starts another run.

An example request:

curl -X POST "$FLOW_WEBHOOK_URL" \
-H "X-Webhook-Key: $FLOW_WEBHOOK_KEY" \
-H "Idempotency-Key: SO-1042" \
-H "Content-Type: application/json" \
-d '{"variables": {"order_id": "SO-1042"}}'

The response carries the new run's ID. Check success as well as the status code: a 200 with success: false started no run.

For example:

{"success": true, "run_id": "…", "message": "…"}

The workflow receives variables as its run inputs. Name each input in the spec, for example "The request carries order_id. Look up that order in @database."

Parallelism​

Parallelism sets how many runs of the deployment can be in flight at once. A run is in flight while it is Queued (queued), Running (running), Resuming (resuming) or Waiting for quota (throttled); a run in Needs review (hitl_paused) isn't. A webhook deployment has no limit until you set one. Enter a number when you create the deployment, or later under Edit; the field's help text shows your organization's maximum. Clear the field to remove the limit. The deployment's page shows it under Configuration.

When the deployment already has that many runs in flight, a request starts no run. Flow answers 429 with the code DEPLOYMENT_PARALLELISM_REACHED and the header Retry-After: 30: send the request again after 30 seconds. The response's details hold the limit (parallelism) and the runs in flight (in_flight). A run of the deployment started with an API key (POST /deployments/{deployment_id}/runs) is held to the same limit and refused the same way.

Runs started by Run now or Automatic Retry start even at the limit, and they count toward it. A run waiting in Needs review also goes back in flight when its review is done, even at the limit. The deployment can then have more runs in flight than its Parallelism, and requests get 429 until enough of them finish.

A request refused with DEPLOYMENT_PARALLELISM_REACHED leaves its Idempotency-Key free. Send it again with the same key and body after Retry-After, and it starts a run if the deployment is below its limit. A repeat of a request that already started its run gets that run back, even when the deployment is at its limit.

Check the run​

Send a GET request to the webhook URL followed by /runs/<run-id>, with the same header. The response gives the run's status, started_at and completed_at. Runs and run statuses lists the statuses; here a run waiting for quota reads throttled.

Errors​

CodeCause
400The deployment isn't a webhook deployment, or it isn't active: it's paused, new and not yet resumed, or Failing.
401The X-Webhook-Key header is missing, its key is wrong, or the deployment has no key. When the header is missing or the deployment has no key, the response also carries WWW-Authenticate: WebhookKey.
404No deployment or run matches the URL.
409The workflow is archived, or a request with the same Idempotency-Key is still starting its run (IDEMPOTENCY_IN_PROGRESS).
422The body isn't JSON, a body is sent without a JSON Content-Type header, or variables isn't an object. Also when the Idempotency-Key is empty or longer than 255 characters, or was already used with a different body (IDEMPOTENCY_KEY_REUSED).
429With the code DEPLOYMENT_PARALLELISM_REACHED, the deployment has as many runs in flight as its Parallelism allows: send the request again after the number of seconds in Retry-After. Any other 429 means your organization has as many runs in flight as it may, the number shown in the footer of the Deployments page. That response has no Retry-After: send the request again once some runs have finished.
503Flow couldn't check the Idempotency-Key (IDEMPOTENCY_UNAVAILABLE). No run was started; send the request again after the Retry-After seconds.

The key is checked before the Idempotency-Key and before whether the deployment is active or archived, so a webhook deployment answers a wrong key with 401 in any state, and so does a deployment with no key. A repeated request with an Idempotency-Key gets its first run back even after the deployment was paused or its workflow archived. When the first request failed after its run was created, the repeat returns that run, which Flow marks failed, and its message says the run failed; send the request again with a new key. A retry sent within 15 minutes of a first request that failed while starting its run gets 409; after that, send it again or use a new key.