API client variables explained: collection, folder, environment and local values

{{baseUrl}} looks simple until it resolves to the wrong value. Was it the collection variable, the folder variable, the environment, a value a script set two requests ago, or a .env file someone loaded? This post explains where variables come from in Requestarium, which one wins, and how to lay them out so you never have to guess.

The layers

From the most general to the most specific:

  1. Collection variables. Defaults for every request in a collection. Good for values that are the same everywhere, like an API version (v2) or a path prefix.
  2. Folder variables. Override the collection for one part of the API. A Billing folder might set its own servicePath.
  3. The selected environment. Values per stage: Local, Staging, Production. This is where hosts and credentials live.
  4. A local .env file, if you loaded one. Values for this session only, never synced, overriding the saved environment. Ideal for personal secrets.
  5. Values set by scripts. pm.environment.set('token', …) in a post-response script makes {{token}} available to the requests after it.
The collection Variables tab with an orderId variable
Collection variables: defaults for every request

On top of that, there are dynamic variables such as {{$guid}} that generate a value each time.

Which one wins

The resolution order is:

  1. Collection and folder variables provide inherited defaults. The nearest folder wins over the collection.
  2. The selected environment overrides matching keys.
  3. A loaded .env file overrides the environment.
  4. Pre-request scripts can change values right before the request is sent.
  5. Post-response scripts can store values for later requests.

You don't have to work it out by hand

Open a request's Variables panel. It lists every variable the request uses, whether it's defined, a preview of its value, and where that value comes from: inherited (collection or folder), environment, global or built-in. A variable that isn't defined anywhere is flagged before you send.

The Variables panel showing each variable, its value and its source, including a local .env file
Each variable with its value and where it came from

In a script, pm.variables.get(name) returns the merged value, the same one the request will use. pm.environment.get(name) reads only the environment.

A layout that scales

For a team with several APIs and stages:

WhereWhatExample
Environment groupOne per API or product areaPayments
EnvironmentOne per stage, inside the groupLocal, Staging, Production
Environment variablesHosts, credentials, tenant IDsbaseUrl, apiKey (secret), tenantId
Collection variablesConstants and defaultsapiVersion=v2, pageSize=20
Folder variablesOverrides for one areaservicePath=/billing
.env filePersonal secrets, production tokenstoken=…

An environment group can declare the variable keys its environments are expected to have, so when someone adds Production, they can see that apiKey is still empty.

Common mistakes

SymptomUsual cause
{{host}} is sent literallyNo environment selected, or the key is missing from it
A request hits staging while "Production" is selectedA collection or folder variable with the same name, and no environment value overriding it. Check the Variables panel
Works in the app, fails in the CLIA value set by a script during manual testing; in a collection run each iteration starts fresh
A teammate's request uses your tokenThe token was saved to a shared environment. Use a .env file or a script-set value instead

In the CLI

The CLI uses the same layers, plus command-line overrides. Later sources win:

Terminal
requestarium run-collection "Payments API" --env Staging \
  --env-file .env \
  --env-var apiKey=CI_PAYMENTS_KEY \
  --var pageSize=5

--env-file, then --env-var, then --var. A data file row (--data) sits between the environment and --var.