Skip to main content
Bruno offers powerful scripting capabilities that allow you to extend and automate your API testing workflows. Here is the complete set of API reference for the scripting feature in Bruno.

Request

The req variable represents the HTTP request object and is automatically available inside your scripting and testing context. It provides methods to access and modify the current request’s properties such as URL, method, headers, body, and other configuration options before the request is sent to the server.
The req object is available in pre-request scripts and test scripts, allowing you to modify request properties before execution and access them after completion.
Here is a complete table for all available methods on the req object. Below is the API documentation for the methods available on req.

req.getUrl()

Returns the full URL of the current request, including any query parameters. Useful for logging, conditional logic, or passing the URL to another variable.

req.setUrl(url)

Overrides the request URL with a new one. Use this in pre-request scripts when you need to dynamically compute or switch the endpoint before the request is sent.

req.getHost()

Get the hostname from the request URL.

req.getPath()

Get the path from the request URL.

req.getQueryString()

Get the raw query string from the request URL.

req.getPathParams()

Extract path parameters using the path template defined in the request.

req.getMethod()

Returns the HTTP method of the current request (e.g. "GET", "POST", "PUT", "DELETE"). Useful for logging or branching logic based on the request type.

req.setMethod(method)

Overrides the HTTP method of the request. Useful when you need to conditionally switch a request’s method in a pre-request script.

req.getName()

Returns the display name of the current request as defined in Bruno. Useful for logging or identifying which request is running in a shared script.

req.getAuthMode()

Returns a string representing the active authentication type for the request. Possible values: "bearer", "basic", "oauth2", "oauth1", "awsv4", "digest", "wsse", or "none".

req.getTags()

Get the current request tags as an array of strings. Useful for conditional logic, filtering, or organizing requests by tag. Returns: Array of strings representing the request tags.

req.getHeader(name)

Returns the value of a specific request header by name. Returns undefined if the header does not exist. Header names are case-insensitive.

req.getHeaders()

Returns an object containing all request headers as key-value pairs. Useful for logging or inspecting headers before the request is sent.

req.setHeader(name, value)

Adds or updates a single request header. If the header already exists, its value is overwritten.

req.setHeaders(headers)

Adds or updates multiple request headers at once by passing an object. Existing headers with matching names are overwritten; others are left unchanged.

req.deleteHeader(name)

Removes a single request header by name. Has no effect if the header does not exist.

req.deleteHeaders(names)

Removes multiple request headers in one call. Pass an array of header names to remove.

req.getBody(options?)

Returns the current request body. For JSON content types, Bruno automatically parses and returns the body as an object. Pass { raw: true } to get the raw string instead. Parameters:
  • options (object, optional): raw (boolean) — when true, returns the raw unparsed body string; otherwise returns the parsed object (default).

req.setBody(body)

Replaces the request body with the provided value. For JSON content type, pass an object — Bruno will serialize it automatically. Only available in pre-request scripts.

req.setTimeout(milliseconds)

Sets a custom timeout (in milliseconds) for the request. If the server does not respond within the specified time, the request is aborted. Overrides the collection-level timeout for this request.

req.getTimeout()

Returns the current timeout value for the request in milliseconds. Useful for logging or conditionally changing the timeout.

req.setMaxRedirects(count)

Sets the maximum number of HTTP redirects Bruno will follow for this request. Set to 0 to disable following redirects entirely.

req.getExecutionMode()

Get the current active execution mode: runner (collection run) or standalone (single request).

req.getExecutionPlatform()

Get the platform: app (desktop) or cli (Bruno CLI).

req.onFail(callback)

Handle request errors with a custom callback. error includes details about the failure.
The onFail function is only available in Developer mode and should be called in pre-request scripts. When using Bruno CLI (v3.0.0+), pass the --sandbox=developer flag.

Response

The res variable represents the HTTP response object and is automatically available inside your scripting and testing context after a request is executed. It contains all the information about the response received from the server, including status codes, headers, body data, and timing information.
The res object is only available in post-request scripts and test scripts, as it contains the response data from the completed request.
Here is a complete table for all available properties and methods on the res object.
The body property is automatically parsed as JSON if the response has a JSON content type. For other content types, it will be a string.
Below are the detailed descriptions for properties and methods available on the res object.

res.status

The HTTP response status code as a number (e.g., 200, 201, 400, 404, 500). Equivalent to calling res.getStatus().

res.statusText

The human-readable HTTP status message that accompanies the status code (e.g., "OK", "Created", "Not Found").

res.headers

A plain object containing all response headers as key-value pairs. Header names are lowercased.

res.body

The response body, automatically parsed as a JavaScript object if the response has a JSON Content-Type. For all other content types, it is returned as a string.

res.responseTime

The total round-trip time in milliseconds from sending the request to receiving the full response.

res.url

The final URL of the response after all redirects have been followed. If no redirects occurred, this is the same as the original request URL.

res.getStatus()

Returns the HTTP response status code as a number. Equivalent to reading res.status.

res.getStatusText()

Returns the HTTP status message string. Equivalent to reading res.statusText.

res.getHeader(name)

Returns the value of a specific response header by name. Returns undefined if the header does not exist. Header lookup is case-insensitive.

res.getHeaders()

Returns an object containing all response headers as key-value pairs. Header names are lowercased.

res.getBody()

Returns the response body. If the response has a JSON Content-Type, the body is automatically parsed into a JavaScript object. Otherwise, it returns the raw string.

res.setBody(body)

Replaces the response body with a new value. This modifies the body as seen by downstream test scripts — it does not alter what was actually returned by the server.

res.getUrl()

Get the response URL after redirects (same information as res.url).

res.getResponseTime()

Returns the total time taken for the request in milliseconds. Equivalent to reading res.responseTime.

res.getSize()

Get the response size in bytes. Returns { body, headers, total }.

Environments

The bru object provides methods for managing environments in Bruno. Environments allow you to maintain different configurations for various deployment stages (development, staging, production, etc.).
Environment variables are specific to the selected environment and can be accessed across all requests in your collection.
Here are all available environment-related methods:

bru.getEnvName()

Retrieves the current environment name.

bru.getEnvVar(key)

Returns the value of an environment variable from the currently selected environment. Returns undefined if the variable does not exist or if no environment is selected.

bru.setEnvVar(key, value, options?)

Set the Bruno environment variable. By default, variables are in-memory only; use { persist: true } to save to disk. Parameters: key (string), value (any), options.persist (boolean, optional).

bru.hasEnvVar(key)

Returns true if the variable exists in the currently selected environment, false otherwise. Useful for guarding reads when a variable may not be set in every environment.

bru.deleteEnvVar(key)

Removes a specific variable from the current environment. Changes are in-memory only for the duration of the run unless the environment is re-saved.

bru.getAllEnvVars()

Returns an object containing all variables in the currently selected environment as key-value pairs. Useful for debugging or iterating over environment config.

bru.deleteAllEnvVars()

Removes every variable from the currently selected environment. Use with caution — this affects all requests in the collection that rely on environment variables.
This action clears all variables from the active environment. It cannot be undone within the same run.

bru.getGlobalEnvVar(key)

Returns the value of a global environment variable. Global variables are shared across all environments and collections in the same Bruno workspace.

bru.setGlobalEnvVar(key, value)

Sets or updates a global environment variable. Useful for storing values that need to be accessible across different environments or collections.

bru.getAllGlobalEnvVars()

Returns an object of all global environment variables as key-value pairs.

Variables

Bruno provides a comprehensive variable system that allows you to manage and access different types of variables throughout your scripts. Variables are resolved in a specific order of precedence, with runtime variables taking the highest priority.
Variable precedence (highest to lowest): Runtime Variables → Request Variables → Folder Variables → Collection Variables → Environment Variables
Here are all available variable-related methods:

bru.getProcessEnv(key)

Returns the value of a Node.js process.env variable. This lets you read OS-level environment variables (e.g. from a .env file loaded in your shell) without storing secrets in your collection files.

bru.getCollectionVar(key)

Returns the value of a collection-level variable. Collection variables are defined in the collection settings and are shared across all requests and folders in the collection.

bru.hasCollectionVar(key)

Returns true if a collection-level variable with the given key exists, false otherwise.

bru.getCollectionName()

Returns the display name of the currently active collection. Useful for logging in shared scripts that run across multiple collections.

bru.getFolderVar(key)

Returns the value of a folder-level variable. Folder variables are defined in the folder settings and are only accessible to requests within that folder.

bru.getRequestVar(key)

Returns the value of a request-level variable. Request variables are defined within a specific request and are only accessible in that request’s scripts.

bru.hasVar(key)

Returns true if a runtime variable with the given key exists, false otherwise. Runtime variables are created with bru.setVar() and exist only for the duration of the collection run.

bru.getVar(key)

Returns the value of a runtime variable. Runtime variables are in-memory only and are used to share data between requests within a single collection run.

bru.setVar(key, value)

Creates or updates a runtime variable. Runtime variables are temporary and only exist during the current collection run — use them to pass data from one request to the next.

bru.deleteVar(key)

Removes a single runtime variable by key. Has no effect if the variable does not exist.

bru.deleteAllVars()

Removes all runtime variables. Use at the start of a run to ensure a clean state.

bru.getAllVars()

Returns an object containing all current runtime variables as key-value pairs. Useful for debugging mid-run state.

bru.getOauth2CredentialVar(key)

Returns the value of an OAuth2 credential variable (e.g. the current access token). This reads from the OAuth2 token store managed by Bruno’s auth layer — not from environment or runtime variables.

bru.resetOauth2Credential(credentialId)

Clears the stored OAuth2 tokens for the given credential ID, forcing Bruno to re-run the OAuth2 authorization flow on the next request that uses it.

bru.getSecretVar(key)

Retrieve a secret from a configured secret manager. Key pattern: <secret-name>.<key-name>.
Secrets must be configured in your collection’s secret manager settings before they can be accessed via bru.getSecretVar(). See Secret Managers for setup details.

Runner

The Runner API provides methods to control the execution flow of your collection runs. These methods are specifically designed for use within the collection runner context, allowing you to skip requests, change execution order, or stop the run entirely.
Runner methods like skipRequest() and stopExecution() only work during collection runs and will have no effect when running individual requests.
Here are all available runner-related methods:

bru.setNextRequest(requestName)

Overrides the default sequential execution order — after the current request finishes, Bruno jumps to the named request instead of the next one in the list. Use in post-request or test scripts. Pass null to stop the run immediately after the current request. Use the request’s display name exactly as it appears in Bruno (not a folder path).

bru.runner.setNextRequest(requestName)

Identical to bru.setNextRequest() — an alternative access path on the bru.runner object. Specify the next request to execute by its display name.

bru.runner.skipRequest()

Skips the current request entirely during a collection run — Bruno moves on to the next request without sending it. Call this in a pre-request script.

bru.runner.stopExecution()

Immediately stops the entire collection run. No further requests are executed after this call. Can be used in pre-request, post-response, or test scripts.

Utilities

The Utilities API provides a collection of helper functions for common tasks such as making HTTP requests, working with cookies, managing tests, and other utility operations. Here are all available utility methods:

bru.sendRequest(options, callback?)

Send a programmatic HTTP request from your script. Supports method, url, headers, data, timeout, httpsAgent, and optional callback(err, res); also supports await without a callback.
Bruno applies your TLS (custom CA, SSL verification), proxy, and client certificate settings to bru.sendRequest() unless you override with httpsAgent.
Custom HTTPS agent (e.g. self-signed):
Custom CA (requires Developer Mode for fs):
Custom HTTPS agents and loading certificates from disk require Developer Mode.

bru.sleep(milliseconds)

Pauses script execution for the specified number of milliseconds. Use this to introduce a delay when polling a slow API or waiting for a background job to complete.

bru.interpolate(string)

Resolves Bruno dynamic variables (e.g. {{$randomFirstName}}, {{baseUrl}}) inside a string and returns the result. Useful when you need a variable-interpolated value inside a script, not just inside a request field.

bru.disableParsingResponseJson()

Prevents Bruno from automatically parsing the response body as JSON, even when the Content-Type is application/json. After calling this, res.getBody() returns the raw string. Call this in a pre-request script.

bru.cwd()

Returns the absolute path of the collection’s root directory on disk. Useful when reading files (certificates, fixtures, config) relative to the collection in Developer Mode.

bru.isSafeMode()

Returns true when the script is running in Safe Mode (the default sandbox), or false when running in Developer Mode which enables require() and Node.js built-ins. Use this to branch logic based on the active sandbox.
See JavaScript Sandbox.

bru.runRequest(requestPathName)

Executes another request in the collection by its name and returns its response. Useful for chaining dependent requests inside a single script without relying on collection runner order.
Do not call bru.runRequest() from a collection-level pre-request script — it can cause an infinite recursive loop. Always use double quotes for the request name.

bru.getTestResults()

Returns the test results for the current request as an array of result objects. Each object contains the test name and its pass/fail status. Use in test scripts to inspect or log outcomes programmatically.

bru.getAssertionResults()

Returns the assertion results for the current request as an array of result objects, each describing the expression, expected value, actual value, and pass/fail status. Use in test scripts.

Cookies

Cookie helpers on bru.cookies are scoped to the current request URL automatically. You can read and iterate cookies synchronously, and write changes with async methods that persist to Bruno’s underlying cookie storage—without constructing a jar or repeating the URL on every call.
For advanced flows (explicit URL, multiple sites in one script), you can still use bru.cookies.jar() below; the jar API is unchanged.

Why use request-scoped helpers?

Jar-based (still valid): you create a jar, pass the site URL into each call.
Request-scoped (simpler): Bruno uses the active request URL for you.
Use whichever style fits your script; both operate on the same stored cookies for the request.

Read methods (sync)

Iteration methods (sync)

Write methods (async)

These update the persisted jar for the scoped URL—use await in async scripts.

Where it runs

Request-scoped cookie helpers are available in pre-request, post-response, and test scripts in both the Node VM runtime and the QuickJS sandbox, matching the environments where your other bru.* script APIs run.
Low-level jar APIs work in pre-request, post-request, and test scripts. Create a jar when you need an explicit URL or jar instance not tied to a single request context.

bru.cookies.jar()

Create a cookie jar instance.

jar.setCookie(url, name, value) / jar.setCookie(url, cookieObject)

Set one cookie: either (url, name, value) or (url, { key, value, domain, path, expires, maxAge, secure, httpOnly, sameSite }).

jar.setCookies(url, cookies)

Set multiple cookies from an array of cookie objects.

jar.getCookie(url, name)

Get a cookie by name; returns the cookie object or null.

jar.hasCookie(url, name, callback?)

Returns a Promise of true/false, or invokes callback(error, exists) if provided.

jar.getCookies(url)

Get all cookies for a URL (array).

jar.deleteCookie(url, name)

Delete one cookie. Domain/path must match how the cookie was set.
Deletion only succeeds when domain and path match the stored cookie.

jar.deleteCookies(url)

Remove all cookies for a URL.

jar.clear()

Clear every cookie in the jar.