Open In App

Explain the concept of local variables in Postman.

Last Updated : 07 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Variables enable you to store and reuse values in Postman. By storing a value as a variable, you can reference it throughout your collections, environments, requests, and test scripts. Variables help you work efficiently, collaborate with teammates, and set up dynamic workflows. In this article, we will learn The concept of local variables in Postman.

Prerequisites

  • Basic HTTP concepts
  • Knowledge of REST API

What are Local Variables in Postman?

The local variables in Postman are also known as the Environment variable. The scope of the local variable is confined to the Environment in which it is created. These are temporary variables that are accessed in your request scripts. Local variable values are scoped to a single request or collection run, and are no longer available when the run is complete. Local variables are suitable if you need a value to override all other variable scopes but don’t want the value to persist once execution has ended.

Key Features of Local Variables:

  1. Scope-Limited: Local variables are defined to the specific script where they are declared. They don’t have access beyond the execution scope of that script.
  2. Temporary Storage: They have a temporary storage for manipulating data within a script, without affecting other scripts or requests.
  3. Dynamic Manipulation: Local variables can helps to perform dynamic operations like data transformations, calculations, or temporary data storage needed during script execution.

Steps to create Local Variable in Postman

Step 1: After downloading and installing the Postman, open the software. Add a new Collection and give it a name like “GFG”.

postman

Step 2: Create a environment ; “GFG“, using the + button in Environments tab as shown below

z176

Step 3: Create a local variable ; ‘var’ and add a initial value as 1

z177

Step 4: Go to your collection and select the environment ; “GFG”

z175

Step 5: Now You can simply paste the API in the space provided and you can call the local variable by {{var}} , then click on Send. Output will be shown in the body with the status code.

API Used

https://jsonplaceholder.typicode.com/posts/?userId={{var}}

Output

Recording-2023-12-07-at-003311


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads