Skip to content

Scripts

The Script tab has two parts: Before request and After response. The collection has its own scripts too, under Manage… > Collection > Scripts. They run in this order: the collection’s before, the request’s before, the request is sent, the collection’s after, then the request’s after.

The Script tab with an after-response script written for Postman's pm.

api and pm are the same object, so scripts written for Postman run as they are. expect is Chai 4.5, as in Postman, and CryptoJS is version 4.2.

A script may run for 10 seconds; time spent waiting for api.sendRequest does not count. Scripts cannot require modules, read files, or reach the network except through api.sendRequest, which respects the production lock.

If a before-request script fails, the request is not sent, and the error names the line. If an after-response script fails, the response is kept and the error shows as a failed row with the checks. console.log output goes to the response’s Console.

Generate from response writes a starting script from the last response, and ⌘B (Ctrl+B) tidies the script you are looking at.