Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Postman Tutorial Part 47 – Local or Temporary Variables in Postman

Posted on 03/16/2025 By admin

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:-

  1. Temporarily store a value to be used/reused in other calculation/requests.
  2. Printing/Debugging the request execution
  3. Override the global, environment, data and collection variables value as local variable will have highest priority always.

We can create local variables in Postman in two ways:-

  1. Using JavaScript way ( var or let)
  2. Using pm sandbox APIs

See the JavaScript syntax below:-

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.

There is an important points about local variables created through JavaScript. You can not use this variable outside of current scope. It means if we create a local variable in “Pre-request Script” of a request, we can not reuse it in Tests tab of same request and in Pre-request and Tests script of any other request and vice – versa. It will give reference error. It restricts scope of local variable again.

Try to use local variable created named “localVar” in Tests tab:-

ReferenceError:-

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:-

pm.variables.set(“”,””)

Syntax to get value of created local variable:-

pm.variables.get(“” )

Unlike JavaScript way of creating local variable, postman sandbox API way gives wider scope to local variable. We can use these local variables within collection.

We can use this local variable in other request as well. I just made a copy of above request.

But remember, if local variables are shared with another request, you must need to run using Collection runner. Otherwise it will give you undefined value not reference error like JavaScript way.

If you have any doubt, feel free to comment below.If you like my posts, please like, comment, share and subscribe.#ThanksForReading

#HappyLearning

Uncategorized

Post navigation

Previous Post: chrome
Next Post: css

Related Posts

xpathYatra – Make Selenium Easy Uncategorized
Git Tutorial 20 – Untracked File Vs Unstaged File Uncategorized
TestNG Tutorials 2: Installation Of TestNG In Eclipse ==> Download And Add To Build Path Way | Make Selenium Easy Uncategorized
selenium 4 features Uncategorized
MultipleGroupNames – Make Selenium Easy Uncategorized
image – Make Selenium Easy Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark