How to get the value of environment variable in Postman?


We can get the value of an Environment variable in Postman at runtime with the help of scripts. This is done with the help of the pm.* function. The script to get the Environment variable can be included either in the Tests or Pre-Request Script tab

To get an Environment variable, the script should be −

pm.environment.get('<name of Environment variable>')

Finally, to get the value of the Environment variable in the Postman console, the script should be −

console.log(pm.environment.get('<name of Environment variable>'))

Let us try to get the value of the Environment variable tutorial.

Step1 − Add the below script to get the value of the Environment variable tutorial and print it in console.

console.log(pm.environment.get('tutorial'))

Step2 − Click on Send to execute a request.

Step3 − After the Response is received, open the Postman Console. It displays postman which is the value set for the Environment variable tutorial.

Updated on: 25-Jun-2021

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements