Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/JonathanHerSa/xolo-api-hub/llms.txt

Use this file to discover all available pages before exploring further.

Pre-request scripts let you generate fresh values immediately before an HTTP request is dispatched — without touching your saved environment. Each script rule is a small template expression that is evaluated at send time and injected into the active variable set for that single request. This is ideal for anything that must be unique or time-sensitive per request: nonce values, HMAC timestamps, test email addresses, or randomly scoped identifiers that would become stale if stored as static environment variables.

Script Format

Pre-request scripts are stored as a JSON array on the request record (column preScriptsJson). Each element is an object with two fields:
FieldTypeDescription
keyStringThe variable name that will be injected
valueStringA template string using {{variable}} syntax
The value field supports the full VariableParser syntax, including all built-in dynamic helpers such as {{$timestamp}}, {{$guid}}, and {{$randomEmail}}.
[
  { "key": "authTimestamp", "value": "{{$timestamp}}" },
  { "key": "requestId",     "value": "{{$guid}}" },
  { "key": "testEmail",     "value": "{{$randomEmail}}" }
]
Rules with an empty 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.
/// Evaluates pre-request script rules against [baseVars].
///
/// [preScriptsJson]  JSON string containing the array of {key, value} rules.
///                   Pass null or an empty string to skip execution.
/// [baseVars]        The current environment variable map. Used as the
///                   resolution context when the value template itself
///                   references other variables.
///
/// Returns a Map<String, String> of computed variable names → values.
/// Merge this into the working variable set before resolving the request.
static Map<String, String> executePreScripts(
  String? preScriptsJson,
  Map<String, String> baseVars,
)
The method returns a plain 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

  1. Parse preScriptsJson as a JSON array.
  2. For each {key, value} rule, call VariableParser.parse(value, baseVars).
  3. Store the resolved string under key in the results map.
  4. Return the full results map to the caller.
If the JSON is malformed, or an individual rule throws during evaluation, the error is logged via AppLogger.warn() and execution continues with the remaining rules.

Using Pre-Script Values

The computed variables are available everywhere in the same request immediately after executePreScripts() returns — including the URL, all headers, all query parameters, and the request body. For example:
URL:    {{baseUrl}}/webhooks?nonce={{requestId}}
Header: X-Timestamp: {{authTimestamp}}
Body:   { "email": "{{testEmail}}", "ref": "{{requestId}}" }
Because the merge happens before 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.
To remove a rule, tap the × icon on the right side of the row. Changes are saved automatically as you type.

Build docs developers (and LLMs) love