Available Objects
In post-response scripts, you have access to:bru- Main Bruno API objectreq- Request object (read-only)res- Response objecttest- Test functionexpect/assert- Chai assertion librariesconsole- Logging functions
Response Object (res)
Theres object represents the HTTP response received from the server.
Properties
number
HTTP status code (e.g., 200, 404, 500)
string
HTTP status text (e.g., “OK”, “Not Found”)
object
Response headers as key-value pairs
any
Response body (automatically parsed if JSON)
number
Response time in milliseconds
string
Final URL after redirects
Methods
function
Returns the HTTP status code
function
Returns the HTTP status text
function
Gets a specific response headerParameters:
name(string) - Header name
function
Returns all response headers as an object
function
Returns the response body (automatically parsed if JSON)
function
Modifies the response bodyParameters:
data(any) - New body data
function
Returns the response time in milliseconds
function
Returns the final URL (useful after redirects)
function
Returns size information about the responseReturns an object with:
header- Size of headers in bytesbody- Size of body in bytestotal- Total size in bytes
function
Returns the raw response data as a Buffer
function
Query the response body using dot notation (callable response)Parameters:
path(string) - Dot-notation path to query
Bruno Object (bru)
Thebru object provides the main Bruno API for managing variables, environment, and request flow.
Variable Management
Runtime Variables
Runtime Variables
Runtime variables exist only during the current request/collection run.
function
Sets a runtime variable
function
Gets a runtime variable (with interpolation)
function
Checks if a runtime variable exists
function
Deletes a runtime variable
function
Returns all runtime variables
function
Deletes all runtime variables
Environment Variables
Environment Variables
Environment variables are associated with the selected environment.
function
Sets an environment variableParameters:
key(string) - Variable namevalue(string) - Variable valueoptions.persist(boolean) - If true, saves to environment file
function
Gets an environment variable
function
Checks if an environment variable exists
function
Deletes an environment variable
function
Returns all environment variables (excluding
__name__)function
Deletes all environment variables
function
Returns the name of the active environment
Global Environment Variables
Global Environment Variables
Collection Variables
Collection Variables
OAuth2 Credentials
function
Gets an OAuth2 credential variable
function
Resets OAuth2 credentials (clears access/refresh tokens)Parameters:
credentialId(string) - The credential ID to reset
Request Flow Control
function
Skips the current request (only in collection runs)
function
Stops the entire collection run
function
Sets the next request to execute in a collection runParameters:
requestName(string) - Name of the next request to run
Utility Functions
function
Interpolates variables in a string or object
function
Returns the collection directory path
function
Returns the collection name
function
Gets a process environment variable from the OS
function
Pauses execution for the specified millisecondsParameters:
ms(number) - Milliseconds to sleep
function
Returns true if running in safe mode (QuickJS runtime)
Cookie Management
function
Creates a cookie jar instance for managing cookies
Utility Methods
function
Minifies JSON (removes whitespace)Parameters:
json(string | object) - JSON to minify
function
Minifies XML (removes whitespace)Parameters:
xml(string) - XML string to minify
Test Results
async function
Returns all test results with summary
async function
Returns all assertion results with summary
Common Patterns
Extract and Save Data
Chain Requests
Error Handling
Response Transformation
Next Steps
Test API
Write test assertions
Pre-request Scripts
Modify requests before sending