Pre-request Scripts

Execute JavaScript before sending a request to set variables, generate tokens, or prepare data.

Pre-request scripts run just before the request is sent to the server. Use them to dynamically set environment variables, generate timestamps, or prepare authentication values.

API Reference

FunctionDescription
setVar(key, value)Create or update an environment variable
getVar(key)Read an environment variable (returns value or undefined)
log(message)Print a message to the browser console

Examples

Set a variable before the request

javascript
setVar("token", "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0");
log("Token set: " + getVar("token"));

Generate a timestamp

javascript
var now = new Date().toISOString();
setVar("timestamp", now);
log("Timestamp: " + now);

Use the variable in your request

After setting a variable with setVar(), reference it in your URL, headers, or body using {{variable_name}}.

Example URL: https://api.example.com/data?t={{timestamp}}

Learn more

On this page