Skip to main content
Variable precedence in Requestly defines how a variable value is resolved when the same variable name exists in multiple scopes. The value is picked based on scope priority, ensuring the most relevant context is always applied.

Precedence order

Runtime Variables → Environment Variables → SubCollection Variables → Collection Variables → Global Variables

How it works

  • Runtime variables have the highest priority. If a runtime variable with the same name exists, it overrides all other scopes for the duration of the session.
  • Environment variables are checked next and override SubCollection, Collection, and Global variables.
  • SubCollection variables apply only within that SubCollection and override Collection and Global variables.
  • Collection variables apply to all requests in the collection unless overridden by a higher scope.
  • Global variables act as the final fallback when the variable is not found in any other scope.
This model makes it easy to reuse variables globally while still allowing precise overrides for environments, collections, or temporary runtime use cases.

Developer style explanation

if (variable_name in runtime_variables) {           // Check runtime
  return runtime_variables[variable_name];
} else if (variable_name in environment_variables) { // Check environment
  return environment_variables[variable_name];
} else if (variable_name in subcollection_variables) { // Check sub-collection
  return subcollection_variables[variable_name];
} else if (variable_name in collection_variables) {  // Check collection
  return collection_variables[variable_name];
} else if (variable_name in global_variables) {      // Check global
  return global_variables[variable_name];
} else {
  return null; // Variable not found in any scope
}

Example scenario

Assume the variable {{base_url}} is defined in multiple scopes:
ScopeValue
Globalhttps://global.api.com
Collectionhttps://collection.api.com
SubCollectionhttps://sub.api.com
Environmenthttps://env.api.com
Runtimehttps://runtime.api.com
If you send a request inside a SubCollection with an active Environment, and a runtime variable with the same name exists, {{base_url}} resolves to: https://runtime.api.com If the runtime variable is removed, the value falls back to the environment variable, followed by SubCollection, Collection, and finally Global based on availability.