Last week we launched our new logo and we were really happy to see that people loved it. That was not all however. We also released new versions of Postman and Newman (docs | GitHub).

As noted in the previous post, the app icon for the packaged app was updated in line with the new Postman logo. Apart from bug fixes, the other big change though is something that a lot of users had requested – pre-request scripting.

Pre-request scripts are similar to test scripts except as the name implies, they are executed just before your request is going to be sent to the server by Postman. Some sample use cases for pre-request scripts are:

  1. Generating values and injecting them in requests through environment variables. For example, you can generate timestamps or hashes of values.
  2. Handle custom authentication protocols.
  3. Read and modify data from JSON or CSV files and inject them into scripts.

The primary flow while working with pre-requests would be setting an environment or a global variable and then using the variable in your HTTP request. Let’s look at an example:

Step 1

Open Postman and click on the “Pre-request scripts” button.

Step 2

Set the request URL to and set the method to POST. Keep the body type as form-data.

Step 3

Inside the pre-request editor, write the script below:

var date = new Date();
var time = date.getTime();
postman.setEnvironmentVariable("currentTime", time);

What we are doing here is generating a timestamp and setting an environment variable. This environment variable will then be used in the Postman request builder interface.

Step 4

Set the environment variable in the form-data key value editor.

Step 5

Create a new environment called “” in the environment manager modal.

Step 6

Select the environment from the selector on the top right.

Step 7

Hit “Send” and analyze the response.

As evident above, the server receives the value of the variable which was dynamically generated.

Pre-request scripts can be used in creative ways and can save you a lot of time. If you come up with an interesting use case, make sure to let us know on Twitter or email! Check out the official docs page here. We will be updating it with more examples continuously.

We have also become regular with updating changelogs for Postman and Newman. Make sure to check them out to stay up to date!