Skip to content
Download

Variable scopes

A name is looked up in five scopes; when the same name exists in several, the later one in this list wins:

  1. Globals — Environments → Globals, plus values scripts write with pm.globals.set(...) or pm.variables.set(...).
  2. Collection variables — defaults saved with the collection.
  3. Active environment variables — the selected environment for the workspace.
  4. Request variables — the request’s Vars tab.
  5. Data row — the current row of a data file in the Collection Runner or kurlo run --data.

If nothing matches, the literal {{name}} is left untouched so the unresolved template is visible.

A name may contain any character except { and } — letters from any alphabet, spaces and colons included — and spaces around it are ignored, so {{токен}}, {{api key}} and {{ token }} all work.

A pre-request script runs before the templates are filled in for good. When it stores a value — pm.environment.set("token", ...), pm.collectionVariables.set(...), pm.globals.set(...) — every {{token}} in the same request already uses the new value. The script itself still sees the request as it was resolved before it ran, and edits it makes through pm.request are kept.

A value may itself contain {{...}}, and Kurlo keeps resolving until nothing changes:

scheme = https
host = api.example.com
baseUrl = {{scheme}}://{{host}}

A request pointed at {{baseUrl}}/users goes to https://api.example.com/users. This is the usual way to keep one place to edit when a whole collection moves to staging.

Resolution stops after 20 rounds. A chain that refers back to itself — a = {{b}}, b = {{a}} — keeps its braces rather than looping, so the send fails with an unresolved-variable message pointing at the real culprit.