What is Pre Requests scripts in Postman?

The Pre-Request scripts are executed before the execution of requests. These scripts are implemented in JavaScript and mainly created to execute pre-requisite conditions like declaring request headers, parameters, variables, or an output.

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.

Incorporate the below JavaScript in the Pre-Request Script tab −

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.

Updated on: 03-Aug-2021


Kickstart Your Career

Get certified by completing the course

Get Started