On this page
Trigger a Generate workflow over HTTP
Start a workflow with an HTTP Trigger node, pass typed inputs in a JSON body with an API key, and shape the reply your caller gets with an HTTP Response node.
This page shows you how to let another system start a workflow with a POST request, and answer that request with what the workflow produced.
Build a workflow that accepts requests
Section titled “Build a workflow that accepts requests”Start the workflow with an HTTP Trigger node and finish it with the reply your caller gets.
-
Open the workflow in the builder
The node library down its left side groups nodes under Triggers, Core, Responses, Tools and Logic.
Open full sizeShown in the enterprise edition. -
Add an HTTP Trigger
Drag HTTP Trigger, from Triggers, onto the canvas as the first node instead of Start. A workflow has one or the other, never both.
-
Declare the inputs
In the trigger node, declare the input variables the caller sends. Each has a name, a type (string, url, number, boolean or object), and may be required or carry a default value.
-
Finish with a response
End the workflow with an HTTP Response node, from Responses, to send a reply your caller defines, or with an End node to return the run’s output.
An HTTP Response node only works after an HTTP Trigger; the builder refuses it in a workflow that starts with Start. The first time you add an HTTP Trigger node, Generate provisions an API key for you, which you then find in Settings, then API Keys.
Call the workflow
Section titled “Call the workflow”Start a run from another system.
-
Use a key scoped for Workflows
The key can call any workflow its owner owns or has been shared, and the run happens as the key’s owner, on their connections.
-
Send the inputs as JSON
POST a JSON object whose keys are the trigger’s input names, as in the example below.
-
Wait for the reply
The request stays open until the workflow finishes; What the caller gets back describes the reply.
curl -X POST "https://<your Generate address>/api/v1/triggers/<workflow-id>" \ -H "X-API-Key: <your key>" \ -H "Content-Type: application/json" \ -d '{"customer_id": "C-1042", "notify": true}'The body must be a JSON object whose keys are the trigger’s input names. Generate checks it before the run starts:
- a required input that is missing, and has no default, is refused;
- a value of the wrong type is refused, such as text sent to a number input;
- keys the trigger does not declare are passed to the workflow as they are.
Start a run without waiting
Section titled “Start a run without waiting”Start a long run, get its id at once, then check on it, follow it or stop it, with the same key.
-
Add mode=async to the call
POST to
/api/v1/triggers/<workflow-id>?mode=asyncwith the same key and body. Generate answers 202 with the run’sexecution_id,statusqueued, andlinksto poll, stream and cancel it; theLocationheader is the poll link. -
Poll the run
GET
/api/v1/triggers/<workflow-id>/executions/<execution-id>. The reply holdsstatus, the step results so far underoutput,http_response,error,failure_code,started_at,completed_at, andfiles. -
Download its files
Each entry in
fileshasfile_name,mime_type,size_bytesand adownload_url, which redirects to a link valid for 15 minutes. -
Follow or stop it
GET the poll link with
/streamadded to receive the run’s events as they happen; a stream opened later replays them from the start, so a dropped connection can reattach. POST the poll link with/canceladded to stop it: a queued run is cancelled at once (200), and a running one is asked to stop (202,cancelling).
curl -X POST "https://<your Generate address>/api/v1/triggers/<workflow-id>?mode=async" \ -H "X-API-Key: <your key>" \ -H "Content-Type: application/json" \ -d '{"customer_id": "C-1042"}'An asynchronous run executes in the background, so the caller can hang up; it shows in the workflow’s Execution History like any other run. A key reads only runs of the workflow in its path: asking for another workflow’s run answers 404.
What the caller gets back
Section titled “What the caller gets back”The request stays open until the workflow finishes.
- With an HTTP Response node, the caller receives the status code, headers, content type and body that node sets. Where the node sets no content type it is JSON, and where it sets no status it is 200.
- Without one, the caller receives status 200 and a JSON object with
execution_idandoutput, the results of the workflow’s steps. - If the run fails, the caller receives status 500 with
execution_idanderror. - Each of these replies carries the run’s id in the
X-Workflow-Execution-Idheader, so a caller can poll the run or download its files afterwards. - An HTTP Response body can list the files the run made with
{{run.files}}: each hasartifactId,fileName,mimeType,sizeBytesand adownloadUrl.
Errors before the run starts
Section titled “Errors before the run starts”| Status | Cause |
|---|---|
| 400 “Workflow does not have an HTTP Trigger node” | Add an HTTP Trigger node, or call a different workflow. |
| 400 “Invalid JSON body” | The body is not valid JSON. Curly quotes pasted from a document are a common cause. |
400 with errors |
An input is missing or has the wrong type; each line names the input. |
| 401, 403 | The key is missing, invalid, revoked, or not scoped for workflows. See API keys. |
| 404 “Workflow not found” | The workflow does not exist, or the key’s owner cannot reach it. |
| 409 | A connection a step needs is not ready for the key’s owner, so nothing ran. Connect it, or bind the step to a shared connection. |
| 409 “runs only asynchronously (mode=async) or on a schedule” | A Map step in the workflow uses Provider batch, which cannot finish while a request waits. Call it with ?mode=async, or schedule it. |
| 503 “Kafka producer unavailable” | Only with ?mode=async: Generate cannot queue the run. Try again shortly, or call without mode to wait for the result. |
If your administrator requires shared accounts for unattended runs, a workflow whose steps use a personal account refuses its next HTTP-triggered run. See Share connections with your organization.
Last updated on