Chain variables in recorder exports
The recorder captures live request/response pairs verbatim. When you
export a session into a script (Postman collection, perf test, test
runner script, or mocks), the captured literals — auth tokens,
order IDs, CSRF values — get baked in. The moment the upstream
service rotates any of them, your generated artefact stops working.
The chain-variables option turns those literals into reusable
variables.
What gets detected
The engine scans every entry’s response for values that show up
later in another entry’s request. Detected sources:
- JSON keys (any depth:
data.user.id,items[0].uuid) - Response headers (
X-CSRF-Token,X-Trace-Id, …) Set-Cookiename/value pairs- URL-shaped headers (
Location,Link,Content-Location) — both
the full URL and each path / query value individually
Detected sinks:
- URL path segments
- URL query string values
- Request headers (including
Authorization: Bearer <token>—
prefix is preserved) - Cookies sent back via
Cookie: application/x-www-form-urlencodedform fieldsmultipart/form-datatext fields (file parts are skipped)- JSON request body — scalar values at any depth
How values become variables
The engine matches exact string occurrences (substrings are ignored
to avoid false positives) and synthesises a stable identifier from
the source path:
| Source | Variable name |
|---|---|
response.body.json.user.id |
user_id |
response.body.json.items[0].uuid |
items_0_uuid |
response.header.X-CSRF-Token |
x_csrf_token |
response.set-cookie.session |
session_cookie |
response.header.Location:query.code |
code |
Each consumer location in a later request is rewritten to reference
{{name}} instead of the captured literal.
Numeric values (12345, 987654321) are excluded by default
because they produce noisy correlations (any short integer that
repeats across unrelated endpoints would otherwise produce a
variable). Opt back in with the Include numeric values flag.
Where to flip the switch
In the extension (Mockarty Capture)
On the Actions tab of the extension’s side panel:
☑ Replace correlated values with
{{var}}
On by default. It only appears when at least one of the available actions exports a
script. The toggle affects every “Save as …” button at once — Postman collection,
functional test, load script, and mocks.
In the Web UI
The recorder session’s Export menu has a toggle checkbox above the format selector.
Via the API
Append ?variableize=1 to any of:
POST /api/v1/recorder/:id/export(HAR)POST /api/v1/recorder/:id/export-postmanPOST /api/v1/recorder/:id/export-perfPOST /api/v1/recorder/:id/export-testPOST /api/v1/recorder/:id/mocks
Via the CLI
# Preview the chain rewrite — variables + extract steps, no download.
mockarty-cli recorder variableize <session-id>
# Inspect with options.
mockarty-cli recorder variableize <session-id> \
--include-numeric --max-vars 32 --entries e1,e2,e3
What ends up in the generated artefacts
| Format | Inline placeholders | Extract / seed wiring |
|---|---|---|
| Postman v2.1 | {{var}} in URL/header/body |
pm.collectionVariables.set(...) events on source entries + variable block seeded with captured sample values |
| Perf script | JS template literal: "prefix/" + user_id |
var name = "<sample>"; declarations at the top + // := comment on source entries pointing at the response path |
| Test script | Same JS template literal | var name = r1.body.x; extraction one-liners after source entries |
| Mocks | {{var}} in http.route / request body / headers |
(no extract step — mocks consume the variable at runtime) |
| HAR | {{var}} in consumer request URL/body/headers |
Sidecar via the X-Mockarty-Variables response header ({variables, extracts} JSON) |
Limitations
- Variables are only inferred from previous responses; cross-
branch flows (e.g. one request whose body uses a value from a
later one) aren’t possible — and shouldn’t be in a real chain. - Very short or trivial values (
true,null,42, status codes)
are filtered out by default. - Identical values that appear in multiple unrelated entries get
one variable; later sources reference the same name. - File parts in multipart bodies are not extracted (binary, opaque).
- Re-running
Variableizeon already-parameterised output is a
no-op — no double-substitution.
What to do when nothing got detected
- Lower the minimum value length via the API (
minValueLength)
— the default is 4 chars. - Toggle Include numeric values if your flow uses bare integer
IDs without any string prefix. - Double-check the captured response actually contains the value
the next request consumes. Network proxies sometimes strip
request bodies; the recorder reports the bytes it saw.