Skip to content

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.

  • pm.environment, pm.collectionVariables, pm.globals and pm.variables
  • pm.request, with method, url, headers and body
  • pm.response, with code, json(), text(), to.have.status and more
  • pm.test and pm.expect, a subset of Chai
  • console.*
  • pm.sendRequest, pm.iterationData, pm.info.iteration and pm.info.iterationCount
  • pm.variables.replaceIn(), which also fills dynamic variables
  • xml2Json() 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.

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.

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.

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.

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.