Postman Tutorial Part 47 – Local or Temporary Variables in Postman
We have seen several types of variables in Postman already in previous posts. In this post, we will learn about Local or Temporary variable in Postman.
A Local or temporary variable is created in to memory only during run time and removed once execution is done. As scope of local variable is limited to duration of execution, we can only create and update it in Scripts of Postman.
We can use local variables for below scenarios:-
- Temporarily store a value to be used/reused in other calculation/requests.
- Printing/Debugging the request execution
- Override the global, environment, data and collection variables value as local variable will have highest priority always.
Creating local variables in Postman:-
We can create local variables in Postman in two ways:-
- Using pm sandbox APIs
This way is good if we want to store some variable temporary. Like you would like to add prices of all books. You need to have some variable to store current addition. You can create local variables in Pre-request Script and Tests.
Try to use local variable created named “localVar” in Tests tab:-
Using Postman Sandbox api:-
If we want to have some temporary variable which can be used within collection or shared temporary variables across all request of collection, we can go for this way.
Syntax to create local variable using postman sandbox APIs:-
Syntax to get value of created local variable:-
We can use this local variable in other request as well. I just made a copy of above request.
If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
You can find all Selenium related post here.
You can find all API manual and automation related posts here.
You can find frequently asked Java Programs here.
1 thought on “Postman Tutorial Part 47 – Local or Temporary Variables in Postman”
Thank you taking the scope part. Its important and makes it easy to understand