Script Format
Pre-request scripts are stored as a JSON array on the request record (columnpreScriptsJson). Each element is an object with two fields:
The
value field supports the full VariableParser syntax, including all built-in dynamic helpers such as {{$timestamp}}, {{$guid}}, and {{$randomEmail}}.
key or empty value field are silently skipped during execution.
Execution
ScriptExecutor.executePreScripts() is called by RequestPipeline (and by CollectionRunnerService for each step in a collection run) before any headers, parameters, or the URL are resolved against the variable map.
Map<String, String>. The caller (RequestPipeline or CollectionRunnerService) merges the result into the working variable map with addAll, so pre-script values override any environment variable with the same name for the duration of that request.
Internal flow
- Parse
preScriptsJsonas a JSON array. - For each
{key, value}rule, callVariableParser.parse(value, baseVars). - Store the resolved string under
keyin the results map. - Return the full results map to the caller.
AppLogger.warn() and execution continues with the remaining rules.
Using Pre-Script Values
The computed variables are available everywhere in the same request immediately afterexecutePreScripts() returns — including the URL, all headers, all query parameters, and the request body. For example:
RequestPipeline calls VariableParser.parse() on any of those fields, every occurrence of {{requestId}} in the same request resolves to the same freshly generated UUID.
Pre-scripts only run for the current request and do not permanently modify the environment. The computed values exist only in the in-memory working variable map for the duration of that single send operation. To persist a value across multiple requests, use a post-response script to store it in the active environment.
Adding a Pre-Request Script in the UI
1
Open the Scripts tab
With a request open in the composer, tap the Scripts tab in the request editor tab bar.
2
Switch to Pre-Request
The Scripts tab contains two sub-tabs: Pre-Request and Post-Request. Select Pre-Request.
3
Add a rule
Tap Add (the
+ button in the top-right of the Pre-Request section). A new empty row appears with two fields: a variable name field and a value/template field.4
Enter the variable name and template
In the left field, type the variable name (e.g.,
requestId). In the right field, enter the template expression (e.g., {{$guid}}). The field uses a monospace font and supports any VariableParser expression.5
Send the request
Tap Send. Pre-scripts are evaluated first; the computed values are injected into the variable set before any part of the request is resolved. You can verify the resolved URL and headers in the response panel.