Skip to content
GenerateDocs
What's new
APITrigger workflows over HTTP
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.

EditionsEnterprise: availableConsumer: availableStorage: availableHealthcare: availableAirgapped: available
Who can do thisAnyone who can edit the workflow; the key needs the API keys privilege.
WhereThe workflow in the builder, then Triggers, then HTTP Trigger.

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.

Start the workflow with an HTTP Trigger node and finish it with the reply your caller gets.

  1. Open the workflow in the builder

    The node library down its left side groups nodes under Triggers, Core, Responses, Tools and Logic.

    The workflow builder’s node library, with HTTP Trigger under Triggers and HTTP Response under ResponsesOpen full size
    Shown in the enterprise edition.
  2. 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.

  3. 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.

  4. 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.

Start a run from another system.

  1. 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.

  2. Send the inputs as JSON

    POST a JSON object whose keys are the trigger’s input names, as in the example below.

  3. Wait for the reply

    The request stays open until the workflow finishes; What the caller gets back describes the reply.

Terminal window
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 long run, get its id at once, then check on it, follow it or stop it, with the same key.

  1. Add mode=async to the call

    POST to /api/v1/triggers/<workflow-id>?mode=async with the same key and body. Generate answers 202 with the run’s execution_id, status queued, and links to poll, stream and cancel it; the Location header is the poll link.

  2. Poll the run

    GET /api/v1/triggers/<workflow-id>/executions/<execution-id>. The reply holds status, the step results so far under output, http_response, error, failure_code, started_at, completed_at, and files.

  3. Download its files

    Each entry in files has file_name, mime_type, size_bytes and a download_url, which redirects to a link valid for 15 minutes.

  4. Follow or stop it

    GET the poll link with /stream added 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 /cancel added to stop it: a queued run is cancelled at once (200), and a running one is asked to stop (202, cancelling).

Terminal window
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.

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_id and output, the results of the workflow’s steps.
  • If the run fails, the caller receives status 500 with execution_id and error.
  • Each of these replies carries the run’s id in the X-Workflow-Execution-Id header, 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 has artifactId, fileName, mimeType, sizeBytes and a downloadUrl.
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