DocsWorkflowsVariables and placeholders

Variables and placeholders

Every step in a run can read what came before it: the trigger's data, what earlier steps answered, and variables. This page covers where those values live, how to put them into a message with {{ }}, and how shared variables carry a value from one run to the next.

What a run knows

Each path of a run carries its own data. It starts with the trigger's data, and each step adds what it produced. Later steps on the same path read it by name.

NameHolds
triggerWhat started the run. A client message's values are under trigger.payload; a webhook's or a run by hand's are under trigger.body.
triggeredAtWhen the trigger fired, in UTC.
status, body, jsonWhat the last Call a URL answered: the HTTP status, the text, and the body read as JSON.
item, indexInside a For each: the current item and its position.
commandWhat a Send to client step got back.
childResultWhat a Run workflow step's run ended with: its run, status and output.
signalPayload, wakePayloadWhat a Wait for signal or Wait for a call received.
lastErrorAfter a step failed and the run carried on: its errorCode and message. See Retries and failures.
joinSucceeded, joinFailedAfter Wait for paths: how many of the paths succeeded and failed.
Your local variablesEach by its own name.

A step that splits the run into paths gives each path a copy of the data so far. From there the paths are separate: a value one path sets is not seen by the others.

Placeholders

Text fields in a step, such as a message, an email subject, a URL or a command's payload, take placeholders: a name in double braces, filled in when the step runs. Greenhouse at {{trigger.payload.celsius}} °C sends Greenhouse at 31.5 °C.

  • A dotted path reaches into the data: {{json.forecast.today}}. {{$shared.NAME}} reads a shared variable.
  • In a JSON field, a value that is only a placeholder keeps its type. { "on": "{{heaterOn}}" } sends true, not the text "true".
  • A placeholder with nothing behind it is filled in as empty text, and the step still runs. The run's history notes which field and which placeholder were missing.
  • A line break in a value becomes a space in a one-line field (an address, a subject, a URL, a header), so a value can't add a line of its own.
  • Which client a step talks to and the command type are used as written. They don't take placeholders.
TipOpen a finished run and look at a step's output to see the exact names a later step can read.

Local and shared variables

The Set variable step keeps a value under a name. Choose how long it lasts:

Keep it forLivesCan
This run (local)In this path's data, until the run ends.Set.
Every run (shared)On the workflow, one value for all its runs and versions.Set, Increment, Decrement, Compare and set.

Shared variables are how one run leaves something for the next: a count of rings today, the last state you alerted on, whether a door is open. They are declared on the workflow with a type and a default, and you can change one by hand from the console.

  • Set writes the value. If two runs set it at the same moment, the last one wins.
  • Increment and Decrement add or take away safely, even with many runs at once. They work on counters only.
  • Compare and set writes only if the variable holds the value you expect now, and tells the next step whether it did (casSucceeded). Use it so only one run acts: "if alerted is false, set it to true, and only then send the alert".

Conditions

An If step, a filter on a trigger, and other conditions compare values: equal, not equal, greater or less than, joined with and, or, and not. They can also call a few functions: the time now, text to lower or upper case, contains, starts with, ends with, is empty and is null.

Types are strict. The number 30 and the text "30" are not equal, and greater or less than works only between two numbers or two pieces of text. A board that sends its readings as text needs to send them as numbers to compare them with numbers. A value that isn't there counts as empty: use is empty to check for it first.

What happens when…

A placeholder names a value the run doesn't have
In a text field, the step runs with that part empty, and the run's history has a warning naming the field. In a condition, the missing value counts as empty: it equals nothing but another empty value, and greater or less than fails the step.
Two runs increment the same counter at once
Both count. Increment and Decrement are made one at a time on the server.
A shared variable is set while a run is using it
The run reads the value as it is when each step runs, not as it was when the run started.
I publish a new version
Shared variables keep their values. They belong to the workflow, not to a version.
A path's data grows past 256 KB
The step that made it too big fails with BRANCH_STATE_TOO_LARGE. Keep only the parts of a large answer that later steps need.
A condition compares text with a number
Equal is simply false and not equal is true. Greater or less than fails the step with EXPRESSION_EVALUATION_ERROR, rather than guessing what you meant.
In depth

Rules and API

Expressions

Behind the console, a value or condition is a JSON object with a kind.

kindFieldsGives
literalvalueThe value.
branchStateRefpathA dotted path into the path's data, falling back to the trigger's data.
sharedVariableRefnameA shared variable.
templatetemplateText with placeholders; a missing value is empty.
jsonPathbaseExpression, pathA JSONPath query into another expression's result.
memberobject, memberA member of another expression's result.
binaryleft, operator, rightEqual, NotEqual, GreaterThan, GreaterThanOrEqual, LessThan, LessThanOrEqual, And, Or. And and Or stop early.
unaryoperator, operandNot, Negate.
functionfunction, argumentsNow, UtcNow, ToString, ToLower, ToUpper, Contains, StartsWith, EndsWith, IsNull, IsEmpty.

A condition saved as a bare string is read as a path (or as true/false) and is rewritten as an object on the next publish.

Fields that take placeholders

Email to, subject, body; Telegram chatId, message; ntfy message, title, tags; Discord message, username, avatarUrl, threadId and each embed's text and links; console notification title, message; Call a URL url, header values and body; Send to client payload; Wait for signal correlation. In a JSON field every string value is filled in; property names are not.

Shared variables endpoints

Under /api/v1/workspaces/{workspaceRef}/workflows/{workflowRef}/variables.

CallPermissionDoes
GET /workflows.readLists them by name, up to 200, with totalCount: varName, varType, valueJson, updatedAt.
GET {variableName}workflows.readReads one.
PUT {variableName}workflows.executeWrites one. It is running state, not part of the design, so it needs execute rather than an authoring permission.

Errors

CodeWhen
TEMPLATE_INVALIDOn save: a placeholder is unclosed or empty. The message names the field.
EXPRESSION_EVALUATION_ERRORAt run time: an expression can't be worked out, such as types that don't compare, or a broken placeholder saved before the check existed.
VARIABLE_NAME_RESERVEDA variable name starts with __, which is kept for the engine's own markers.
VARIABLE_NOT_A_COUNTERIncrement or Decrement on a variable that isn't a counter.
VARIABLE_EXPECTED_MISSINGCompare and set with no expected value.
BRANCH_STATE_TOO_LARGEA path's data would pass 256 KB.
SHARED_VARIABLE_UNDECLAREDA warning on save: $shared.NAME reads a variable no step sets.

Rules worth knowing

  • Keys starting with __ in a path's data are the engine's own: where it is parked, its join, its retry count, its loop position.
  • There is no conversion between text, numbers and true or false anywhere in an expression. Equal across kinds is false, not an error; ordering across kinds is an error. Objects and lists compare equal by content, in any property order.
  • A shared variable's resetPolicy is accepted in a definition but not acted on yet. Reset a counter with a Schedule and a Set.