Baton Manual

Chapter 13

Flows

A collection run sends every request in tree order. A flow is for when the order is yours to set: log in first, read a value out of what it answered, go one way or another on it, run three calls side by side, walk a list one item at a time, and write down what happened. You build it on a canvas, and it is a file in your repository like everything else, flows/<slug>.flow.yaml.

Flows are listed under the collections, in the Flows part of the drawer. New flow… in its + (or in the + beside the environment) asks for a name and opens an empty canvas. The demo workspace comes with one, User onboarding.

13.1The canvas

The demo flow after a run, top to bottom on a phone. — 1: Run the flow; 2: Add a step; 3: A step and how its run went; 4: Back to the requests
  1. Run the flow
  2. Add a step
  3. A step and how its run went
  4. Back to the requests
Figure 36: The demo flow after a run, top to bottom on a phone.

On a phone a flow has a screen of its own, and runs from top to bottom. 1 runs it, 2 adds a step — pick its kind — and 4 goes back to the requests. Each card, 3, shows what the step is and, after a run, how it went.

The small circle at the bottom of a card is its output port: drag it onto another card to make that one wait for this one, or tap it to add a step after it. An If, a Switch and a Loop have a port for each way out, named above it. Tap a link, or the dot in its middle, to select it, then tap the × that takes the dot’s place to remove it. Hold a finger on an empty spot to open a menu that adds a step there. Drag a card to move it, drag the background to pan, and pinch to zoom.

13.2Kinds of step

Adding a step: one of seven kinds.
Figure 37: Adding a step: one of seven kinds.
KindWhat it does
RequestSends one of your requests, the way Send sends it.
LogWrites a message into the run — say, which post was made.
IfGoes on from true or from false, as a condition holds or not.
SwitchGoes on from the case that matches a value, or from default when none does.
LoopRuns the steps after its each port once per item of a list, then goes on from done.
Get variableReads values out of a response the flow already has, for the steps after it.
Set variableGives variables a value, for the steps after it.

Only a request sends anything. The other kinds take no time: each does its work the moment the steps before it are done.

Anywhere a step takes text, {{name}} reads a variable: the environment’s, and anything a step before this one read or set. {{steps.login.status}} is the status the step login answered, and {{steps.login.outcome}} whether it passed, failed or was skipped. A secret never reads in a Log, a Set, a condition or a loop’s list — those are written down, and a secret must not be.

13.3A step

Tap a card to open what it does — in a sheet from the bottom of the screen. Every kind has a name for the canvas and Runs after, the steps it waits for, as chips to switch on and off; one that would close a loop is greyed out, since a flow never runs in a circle.

The If in the demo flow, after a run. — 1: Its last run: the way it went; 2: The value to look at; 3: Delete the step; 4: Back to the canvas
  1. Its last run: the way it went
  2. The value to look at
  3. Delete the step
  4. Back to the canvas
Figure 38: The If in the demo flow, after a run.

1 is the step’s last run — for an If, the way it went. An If is three parts: 2 the value to look at, then how it is tested — is not empty, is empty, equals or does not equal — and, for the last two, what to compare it to. Empty means nothing, false, 0 or null; values compare as text. 3 deletes the step, 4 closes the sheet.

The other kinds:

13.4Running it

Press Run. Each request shows the status it answered and whether that counts as a pass, an If marks the way it went, and a Log shows what it wrote. Links turn green or red with the step they come from, and while a request waits for an answer, dots move along the link into it. A skipped step is drawn faded.

Every request is sent the way Send sends it: with its collection’s auth and variables, and its own scripts and tests. It fails when it cannot be sent, when a test fails, or when its status is not the one it expects — any status of 400 or more, unless you set another. Inside a loop, a step’s result shows one chip per item.

When a step fails, the steps that wait for it are skipped, and the rest of the flow goes on. A step marked Keep going if this fails does not stop the steps after it, and does not fail the flow. Two steps side by side never see each other’s values, so which one answers first cannot change the result.

13.5The environment it runs in

A flow runs in the environment that is active, unless you choose one for it in the toolbar. A flow with its own environment always uses that one’s variables and secrets — whichever is active — and the choice is saved in the flow file, so a teammate’s run and the worker’s do the same. Values a run read or set stay for the session, the same as values a script sets; a run in a flow’s own environment leaves the active one’s session alone.