What are the different types of variables in Postman? How and when to use them?

Four types of variables and their scopes

Pricilla Bilavendran


Dear People,

I hope you are all safe!

Today we are going to learn something in Postman which will be very helpful and save our time in most of the scenarios.

If you have worked on any programming language, you would have worked with variables with different scopes. They are nothing but placeholders to hold some value or result of some expressions. We have the same variable concept in Postman with few scopes.

Variables here are typically used in a context where you need to replace values in request bodies, make assertions for the response body and use them in pre-request scripts.

Let’s try to understand different variable scopes in Postman.

Different types of variable scopes are as below:

  1. Global
  2. Collection
  3. Environment
  4. Local
  5. Data variables (Please refer this post, data driven approach handles with data variables)

1. Global

What are Global Variables and when should they be used?

Global variables are the general-purpose variables and should be avoided whenever possible. These variables are available to all the requests under that workspace. Generally, the timestamp, session ID will be stored globally.

Working With the Global Variables

Click on the “Eye” icon near the environment selector, and that will open a popup/context window with details around the current global variables.

How are they created?

Now create a new variable by entering the variable name and its initial value.

pm.globals.set("variable_key", "variable_value");
//exampleconst moment = require('moment');//to set the past date…