- Trending Categories
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 use Global Variable in Postman Request?
We can use a Global variable in Postman Request. . We can set, get and clear a Global variable at runtime using the scripts. This is achieved by the pm.* function. The script to use a Global variable can be included either in the Tests or Pre-Request Script tab
To set a Global variable, the script should be −
pm.globals.set('<name of Global variable>', '<value of variable>')
To get the value of a Global variable, the script should be −
pm.globals.get('<name of Global variable>')
To get the value of the Global variable in the Postman console, the script should be −
console.log(pm.globals.get('<name of Global variable>')
To delete a Global variable, the script is −
pm.globals.unset('<name of Global variable>')
Let us try to work with a Global variable g.
Step1 − Add the below script to set the value value1 for the Global variable g.
pm.globals.set('g', 'value1')
Step2 − Add the below script to get the value of Global variable g and print it in console.
console.log(pm.globals.get('g'))
Step3 − Add the below script to delete the value of Global variable g and verify it.
pm.globals.unset('g')) console.log(pm.globals.get('g'))
Step4 − Click on Send to execute a request.
Step5 − After the Response is received, open the Postman Console. It first displays value1 which is the value set for the Global variable g. Next, it displays undefined since the value of the Global variable g has been deleted in the Step3.
- Related Articles
- How to set a global variable in Postman?
- How to create a Global Variable in Postman?
- How to create and use Global Variable in swift
- How to see request logs in Postman console?
- How to create a PUT request in Postman?
- How to create a DELETE request in Postman?
- How to create a POST request in Postman?
- How to use a global variable in a Python function?
- How to clear the global variables in Postman?
- Global Scope Variables in Postman?
- What is Pre-Request Script in Postman?
- How to share Session ID Cookie with another request using Postman?
- How to use Sessions in Postman?
- How to declare a global variable in C++
- How to declare a global variable in PHP?
