- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 Use Environment Variables in Postman?
We can use Environment Variables in Postman. We can configure, obtain and delete an Environment variable at runtime with the help of scripts. This is achieved by the pm.* function. The scripts to use an Environment variable can be included either in the Tests or Pre-Request Script tab
.To set an Environment variable, the script should be −
pm.environment.set('<name of Environment variable>', '<value of variable>')
To get an Environment variable value, the script should be −
pm.environment.get('<name of Environment variable>')
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>'))
To delete an Environment variable, the script should be −
pm.environment.unset('<name of Environment variable>')
Let us try to use an Environment variable env_variable1.
Step1 − Add the below script to set the value of an Environment variable.
Step2 − Add the below script to get the value of Environment variable env_variable1 and print it in console.
Step3 − Add the below script to delete the value of Environment variable env_variable1 and verify it.
Step4 − Click on Send to execute a request.
Step5 − After the Response is received, open the Postman Console. It first displays val1 which is the value set for the Environment variable env_variable1. Next, it displays undefined since the value of the Environment variable env_variable1 has been deleted in Step3.
- How to Create an Environment in Postman?
- Python Environment Variables
- MySQL Environment Variables
- How to Set environment variables using PowerShell?
- How to get the value of environment variable in Postman?
- Perl CGI Environment Variables
- How to clear the global variables in Postman?
- What is an Environment Variable in Postman?
- CGI Environment Variables in Python
- Global Scope Variables in Postman?
- How to use Sessions in Postman?
- C program to print environment variables
- Where can I set environment variables that crontab will use?
- How to use dynamic GUID in Postman?
- How do I pass environment variables to Docker containers?