Skip to main content
Post-response scripts execute after receiving the HTTP response, allowing you to extract data, save variables, and process the response.

Available Objects

In post-response scripts, you have access to:
  • bru - Main Bruno API object
  • req - Request object (read-only)
  • res - Response object
  • test - Test function
  • expect / assert - Chai assertion libraries
  • console - Logging functions

Response Object (res)

The res 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 bytes
  • body - Size of body in bytes
  • total - 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)

The bru object provides the main Bruno API for managing variables, environment, and request flow.

Variable Management

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 are associated with the selected environment.
function
Sets an environment variableParameters:
  • key (string) - Variable name
  • value (string) - Variable value
  • options.persist (boolean) - If true, saves to environment file
When persist: true, only string values are allowed. Non-string values will throw an error.
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 are shared across all environments.
function
Sets a global environment variable
function
Gets a global environment variable
function
Deletes a global environment variable
function
Returns all global environment variables
function
Deletes all global environment variables
Collection-level variables defined in collection settings.
function
Sets a collection variable
function
Gets a collection variable
function
Checks if a collection variable exists
function
Deletes a collection variable
function
Returns all collection variables
function
Deletes all collection variables
Read-only access to folder and request-level variables.
function
Gets a folder-level variable
function
Gets a request-level variable

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
Returns a Promise.
function
Returns true if running in safe mode (QuickJS runtime)
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