How to get the value of environment variable in Postman?

PostmanREST APISOAP API

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.

raja
Published on 25-Jun-2021 15:00:52
Advertisements