- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.