Skip to content
Download

Variable scopes

pm.variables, pm.globals, pm.environment, and pm.collectionVariables all expose the same four methods:

MethodDescription
.get(key)Read a variable
.set(key, value)Write a variable
.unset(key)Delete a variable
.clear()Clear all variables

They differ in which scope they touch:

ScopeReadsWrites
pm.variablesAll scopes, in precedence order: data row → request → environment → collection → sessionThe session scope
pm.globalsThe session scopeThe session scope
pm.environmentThe active environmentThe active environment
pm.collectionVariablesThe request’s collectionThe request’s collection, saved back to the collection after the send

Kurlo has a single runtime variable scope, so pm.globals and pm.variables.set write to the same place — they are aliases, not two separate stores.

pm.variables.replaceIn(text) fills every {{name}} in a string from the scopes above, plus {{$guid}} and the other dynamic variables — handy for signing the URL a request will actually hit. A name nothing defines is left as written.

Globals persist. They are saved with your data, survive a restart, and are shared across every workspace. Edit them under Environments → Globals in the sidebar; a value a script writes appears there after the send. In kurlo run they come from --globals / --global-var and can be written back with --export-globals.

pm.collectionVariables.set persists: after the request finishes, the value is written onto the collection’s variables (a Git-backed workspace records it in collection.yml). An existing row keeps its id, enabled state, secret flag, and description; only the value changes.

// Cache a value for every later request in the collection.
pm.collectionVariables.set("lastOrderId", pm.response.json().id)