Getting Started GuideVariablesOverview

Variables

With the release of v1.28.0, we’ve shifted to treating all Request Variables as strings instead of inferring the data type from the value. See discussion for more information.

Overview

Variables in the Bruno allow you to store dynamic values that can be reused across multiple API requests, environments, and workflows. This feature enhances flexibility, maintainability, and efficiency by enabling you to manage frequently changing data points such as tokens, environment-specific URLs, or user-defined values in one place.

Types

There are 6 types of variables you can create:

Additionally, Process Environment Variables can be defined in an external environment configuration file:

Runtime variables get the highest precedence. Process Environment Variables are accessed using the {{process.env.VAR_NAME}} syntax and hence don’t compete with the above.

Variable Precedence and Scope

When a variable is accessed, the following precedence is used to determine which value is used:

↑ Higher Precedence
↓ Broader Scope
Runtime Variables
Request Variables
Folder Variables
Environment Variables
Collection Variables
Global Variables

Runtime variables get the highest precedence. Process Environment Variables are accessed using the {{process.env.VAR_NAME}} syntax and hence don’t compete with the above.

Variable Storage

Each variable has its own storage location either within your collection file or within the app’s memory. All storage is local.

Variable TypeStorage Location
Collection<collection-name>.bru
Folder<folder-name>.bru
Request<request-name>.bru
Environment<env-name>.bru
RuntimeLocal storage
GlobalLocal storage
Process EnvironmentSeparate .env file

Variable Data Type

All variables are stored as strings. Bruno does not infer or change the data type of the variable based on the value you set.

Debugging Variables in Console

You can access and debug variables in the console using the following pattern:

The pattern follows bru.get[Type]Var(key) where:

  • [Type] is the variable type (Runtime, Request, Folder, etc.)
  • key is the variable name you want to access

Example:

// Basic syntax: console.log(bru.get[Type]Var(key))
console.log(bru.getVar('myVar'))           // Runtime variables

Scripting API

Please see the Scripting API for more information on how to access variables in your scripts.