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.
| Layer | Runs | Typical Use |
|---|---|---|
| Before All | Once, before the first step | Auth setup, fixture seeding, fetching shared data |
| Step Pre-Script | Before each individual step | Mutating headers, computing dynamic values, setting flow vars |
| Step Post-Script | After each individual step | Parsing the response, extracting values, custom logging |
| After All | Once, 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.
| Snippet | What it does |
|---|---|
| GET request | Send a basic GET request and log the JSON body. |
| POST request | Send a POST with a JSON body using fetch. |
| Register user | Register a new user with a random username generated via {{random.string}}. |
| Login & set token | Log in and store the returned token as a flow variable with at.flow.set("token", token). |
| Set flow variable | Store a value all steps can read via {{flow.key}}. |
| Get environment | Read an environment variable with at.environment.get("key"). |
| Set environment | Write an environment variable with at.environment.set("key", "value"). |
| Console log | Log 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.
| Snippet | What it does |
|---|---|
| GET request | Send a basic GET request. |
| POST request | Send a POST request with a JSON body. |
| Slack notification | POST a Slack webhook with a "Flow run finished!" message. |
| POST JSON report | Call at.export.json() and POST the OTEL JSON to your endpoint. |
| POST HTML report | Call at.export.html() and POST the HTML report (e.g., to an email API). |
| POST PDF report | Call await at.export.pdf() and POST the PDF binary. |
| Get flow variable | Retrieve a previously set flow variable with at.flow.get("key"). |
| Console log | Log 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.
| Snippet | What it does |
|---|---|
| Set header | Add or override a request header with at.request.setHeader("X-Custom", "value"). |
| Set flow variable | Store a value accessible via {{flow.key}}. |
| Get flow variable | Retrieve a previously set flow variable. |
| Set environment | Set an environment variable. |
| Console log | Log 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.
| Snippet | What it does |
|---|---|
| Extract from response | Parse the JSON response and store a value: var data = at.response.json(); at.flow.set("key", data.value); |
| Log response status | Log the response status code with at.response.status(). |
| Set flow variable | Store a value accessible via {{flow.key}}. |
| Get flow variable | Retrieve a previously set flow variable. |
| Set environment | Set an environment variable. |
| Console log | Log 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.
| Namespace | Before All | Pre-Script | Post-Script | After 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.