We can create Pre-Request Script to define the sequence of execution of requests in a Collection. A Pre-Request Script is also utilized for scenarios where value returned from a request is required in the following request or a value returned from a request should be captured prior to the next request.
These scripts are defined in the Pre-request Script tab in Postman.
console.log("This is a Postman Tutorial in Tutorialspoint")
Send a GET request for an endpoint.
Postman Console Output −
Here, the message - This is a Postman Tutorial in Tutorialspoint gets displayed prior to the execution of the GET request since it has been added as a part of the Pre-Request Script.
A Pre-Request Script can be added for a Collection with the below steps −
Step1 − Click on the three dots to the right of the Collection name in the sidebar. Then click on Edit.
Step2 − EDIT COLLECTION window shall open. Select the Pre-Request Scripts tab and then add a script. Finally, click on the Update button.