Scripts
A request has a Scripts tab for a pre-request script and a test script. They use a pm.* API that is compatible with Postman for common needs.
The pm API
Section titled “The pm API”pm.environment,pm.collectionVariables,pm.globalsandpm.variablespm.request, with method, url, headers and bodypm.response, withcode,json(),text(),to.have.statusand morepm.testandpm.expect, a subset of Chaiconsole.*pm.sendRequest,pm.iterationData,pm.info.iterationandpm.info.iterationCountpm.variables.replaceIn(), which also fills dynamic variablesxml2Json()in test scripts, as in Postman, plus a snippet for SOAP responses
Test results and console output appear in the Tests and Console tabs of the response panel.
What happens when a script fails
Section titled “What happens when a script fails”A pre-request script that errors cancels the send. A test script that errors still shows the response. Variable changes from a script are saved, and secret variables stay encrypted. One run can change up to 200 variables.
The sandbox
Section titled “The sandbox”Codestamp runs each script in a QuickJS sandbox that it creates fresh and throws away afterwards. The sandbox has no access to files or processes.
| Limit | Value |
|---|---|
| Memory | 64 MB |
| Stack | 512 KB |
| Time | 2 seconds |
The time limit stays active while the script’s result is read.
pm.sendRequest
Section titled “pm.sendRequest”The only network access from a script is pm.sendRequest, in a pre-request or a test script. It takes a URL string or an object { url, method, header, body } (raw or urlencoded body) and a callback (err, response). It runs synchronously through the same HTTP client and under the same validation rules as a request card.
A script can make 10 calls, and each call can take 10 seconds. Time spent waiting on the network does not count against the 2 seconds.
Related
Section titled “Related”Import brings Postman scripts along: collection and folder scripts are merged in front of the request’s script, in Postman’s order of execution. See Import and export.