Skip to main content
Post-response scripts close the loop between an API response and your next request. After every successful HTTP call, Xolo evaluates a set of JSONPath extraction rules against the response body and stores the matched values as environment variables. This is how you implement request chaining — for example, authenticating with a login endpoint, capturing the returned access token, and automatically injecting it as a Bearer header in every subsequent request — without any manual copy-and-paste.

Script Format

Post-response scripts are stored as a JSON array on the request record (column scriptsJson). Each element is an object with two fields:
Rules with an empty key or empty path are silently skipped.

JSONPath Syntax

Xolo uses the json_path Dart package for JSONPath evaluation. Expressions follow standard JSONPath notation: When a path matches multiple nodes, ScriptExecutor uses the first match. If the path matches nothing, the variable is set to the sentinel value '[No Match]' rather than being omitted, so you can immediately see in the UI that the extraction failed.

ScriptExecutor.testPostScripts() Signature

This method is intentionally non-persisting — it is used by the Scripts tab’s Test button and by unit tests. The actual persistence path (CollectionRunnerService._applyPostScripts()) calls XoloRepository.upsertVariable() for every successfully matched value.

Live Testing

The Scripts tab provides a Test button (▶) in the Post-Request section header. Tapping it calls testPostScripts() against the most recently received response body — the request is not re-sent. Each extraction rule row displays the matched result inline beneath it, highlighted in orange for a match or red for an error, so you can iterate on your JSONPath expressions rapidly without consuming API rate limits.
Test your JSONPath expressions in the Scripts tab before running a full collection — the inline result shows the extracted value without re-sending. This is especially useful when the endpoint you are extracting from is rate-limited or has side effects.

Request Chaining

When you send a request from the composer, successfully matched values are upserted into the active environment via XoloRepository.upsertVariable(). This means subsequent requests in the same session will resolve {{authToken}} (or whatever key you chose) from the environment automatically, without any additional configuration. A complete token-chaining workflow looks like this:
After the login request completes, authToken and currentUserId are live in the environment. Any subsequent request can reference them:
No manual environment editing is needed between the two requests.

Collection Runner Integration

When the collection runner executes a step, post-scripts run after assertions are evaluated and before the next step begins. Extracted values are merged into the shared workingVars map that flows through the entire run:
_applyPostScripts both updates workingVars for the next iteration of the loop and persists each matched value to the database via upsertVariable, so the extracted token survives even if the run is interrupted.
Variable extraction from one step flows into the next, enabling full authentication + resource workflows. For example: step 1 logs in and captures {{authToken}}; step 2 creates a resource using that token and captures {{resourceId}}; step 3 fetches and asserts on that resource.