Scripting

Lifecycle scripts (Before All / After All) and per-step pre/post scripts let you run arbitrary JavaScript around your flow.

Three Scripting Layers

Atrahasis flows expose three places to run JavaScript. Each one has a different scope and purpose.

LayerRunsTypical Use
Before AllOnce, before the first stepAuth setup, fixture seeding, fetching shared data
Step Pre-ScriptBefore each individual stepMutating headers, computing dynamic values, setting flow vars
Step Post-ScriptAfter each individual stepParsing the response, extracting values, custom logging
After AllOnce, after the last step (regardless of success or failure)Reporting, webhook notifications, cleanup

Both lifecycle scripts and step scripts share the same JavaScript runtime and the same at.* API. The difference is which fields of at.* are meaningful in each context (see the API matrix below).

Lifecycle Script Editor

Click Before All (sticky at the top of the step list) or After All (sticky at the bottom) to open the lifecycle editor in place of the step detail panel.

Editor Layout:

  • Header bar: Shows the script name (Before All / After All) on the left and a ▷ Try button on the right.
  • Code editor (center): CodeMirror-based JavaScript editor with syntax highlighting and autocomplete.
  • Snippets panel (right): Curated snippets you can click to insert into the editor. The list differs per hook (see the snippet tables below).
  • Console (bottom, collapsible): Captures everything you write with console.log. Click the bar to expand or collapse.

Try button: Runs the script standalone using the currently selected environment, without executing any steps. The button shows Trying... while running. Use it to iterate quickly on a script without launching a full flow run.

Before All Snippets

The right-hand panel of the Before All editor offers these starter snippets. Each one is a click away.

SnippetWhat it does
GET requestSend a basic GET request and log the JSON body.
POST requestSend a POST with a JSON body using fetch.
Register userRegister a new user with a random username generated via {{random.string}}.
Login & set tokenLog in and store the returned token as a flow variable with at.flow.set("token", token).
Set flow variableStore a value all steps can read via {{flow.key}}.
Get environmentRead an environment variable with at.environment.get("key").
Set environmentWrite an environment variable with at.environment.set("key", "value").
Console logLog a message to the console output.

After All Snippets

The After All snippet list is reporting-heavy: this is the only place where at.export.* returns meaningful data, because the run has just finished.

SnippetWhat it does
GET requestSend a basic GET request.
POST requestSend a POST request with a JSON body.
Slack notificationPOST a Slack webhook with a "Flow run finished!" message.
POST JSON reportCall at.export.json() and POST the OTEL JSON to your endpoint.
POST HTML reportCall at.export.html() and POST the HTML report (e.g., to an email API).
POST PDF reportCall await at.export.pdf() and POST the PDF binary.
Get flow variableRetrieve a previously set flow variable with at.flow.get("key").
Console logLog a message to the console output.

Step Pre-Script Snippets

Each step has a Pre-Script tab in the request editor. The same snippet panel appears on the right.

SnippetWhat it does
Set headerAdd or override a request header with at.request.setHeader("X-Custom", "value").
Set flow variableStore a value accessible via {{flow.key}}.
Get flow variableRetrieve a previously set flow variable.
Set environmentSet an environment variable.
Console logLog a message to the console output.

Step Post-Script Snippets

The Post-Script tab runs after the step's response arrives. at.response is populated here.

SnippetWhat it does
Extract from responseParse the JSON response and store a value: var data = at.response.json(); at.flow.set("key", data.value);
Log response statusLog the response status code with at.response.status().
Set flow variableStore a value accessible via {{flow.key}}.
Get flow variableRetrieve a previously set flow variable.
Set environmentSet an environment variable.
Console logLog a message to the console output.

at.* API Availability

Not every part of the at namespace is meaningful in every script context. The matrix below shows where each subnamespace returns useful data.

NamespaceBefore AllPre-ScriptPost-ScriptAfter All
at.flow.get/set
at.environment.get/set
at.request.*✓ (mutate outgoing request)
at.response.*✓ (read step response)
at.export.json/html/pdf✓ (run results available)

For the full at.* API reference (every method, signature, and return type), see the dedicated Scripting API guide section.