
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Creating Variables Using Pre-request Script in Postman
We can create variables using Pre-Request Script in Postman. We can set, update, or clear variables prior to the execution of the actual request. To set an Environment variable, we have to add the below script under the Pre-Request Script tab.
postman.setEnvironmentVariable(name of variable, value of variable)
To set a Global variable, we have to add the below script under the Pre-Request Script tab.
postman.setGlobalVariable(name of variable, value of variable)
Step1 − Select an Environment – Environment_Test from the No Environment dropdown.
Step2 − In the address bar enter {{URL}} (an Environment variable available to the Environment_Test). Hover over {{URL}} to find the Scope of the variable as Environment. Also, it is represented as E.
Step3 − Navigate to the Pre-Request Script tab and add the below script −
postman.setEnvironmentVariable('tutorial','postman')
This shall create a variable within the Environment_Test Environment having the name tutorial and value postman.
Step4 − Click on the Send button and search for the tutorial variable by clicking the eye icon.