Difference between global and local variables in Postman
Last Updated :
29 Jul, 2024
Postman is a powerful API development tool which offers a feature known as environment variables. These variables are used for efficient testing and development of APIs by allowing users to manage dynamic values across requests easily.
Difference between global and local variables in Postman
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. Let's see the difference between global and local variables in Postman
Global Variables | Local Variables |
---|
These are independent of environments and function outside the environment. Users are not required to create an environment for global variables. Through global variables, we can access data between collections, test scripts, requests, and environments. | These are temporary variables that will only function inside the environment they were created in. When you change the environment, the variable will stop its access, and an error will occur. |
Global variables are accessible across different requests within a collection. They persist throughout the entire collection run. | Local variables are specific to a particular request. They exist only for the duration of that request and are not accessible outside of it. |
You define global variables at the collection level or in the collection's pre-request scripts. These variables are available to all requests in that collection. | Local variables are typically set in the pre-request script of a specific request or dynamically during the request execution. |
Useful for storing data that needs to be shared across multiple requests, such as authentication tokens or common configuration settings. | Ideal for the temporary storage of data relevant only to a particular request, helping maintain request-specific context without affecting other parts of the collection. |
Steps to create Global Variable
Step 1: After downloading and installing the Postman, open the software. Add a new Collection and give it a name like “GFG”.

Step 2: Select the environment quick look icon Environment quick look icon in the workbench as shown. Next to Globals , select Edit (or Add if no variables have been added yet) .
Step 3: Add a variable named geek and give it an initial value of GeeksforGeeks as shown below

Step 5: When you hover, on the name of your collection, 3 dots will appear. Click on those 3 dots, and then click on “Add new request”

Step 6: Now You can simply paste the API in the space provided and you can call the global variable by {{geek}} , then click on Send. Output will be shown in the body with the status code.
Example: In this example, we will create a global variable, id with a initial value=1. We will call API like:
https://jsonplaceholder.typicode.com/posts/?userId={{id}}
Ouput
Steps to create Local VariableStep 1: After downloading and installing the Postman, open the software. Add a new Collection and give it a name like “GFG”.

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

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

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

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}}
the
Output:
Output
Similar Reads
Difference between Local Variable and Global variable
Local variables are declared within a specific block of code, such as a function or method, and have limited scope and lifetime, existing only within that block. Global variables, on the other hand, are declared outside of any function and can be accessed from any part of the program, persisting thr
2 min read
Difference between static and non-static variables in Java
There are three types of variables in Java: Local VariablesInstance VariablesStatic Variables The Local variables and Instance variables are together called Non-Static variables. Hence it can also be said that the Java variables can be divided into 2 categories: Static Variables: When a variable is
4 min read
Difference Between SSH Local and Remote Port Forwarding
SSH stands for "Secure Shell" or "Secure Socket Shell". It is a cryptographic network protocol that allows two computers to communicate and share the data over on insecure network such as the Internet. SSH protocols protect the network from various attacks. Local Port ForwardingLocal Port Forwarding
6 min read
Difference between Variable and get_variable in TensorFlow
In this article, we will try to understand the difference between the Variable() and get_variable() function available in the TensorFlow Framework. Variable() Method in TensorFlow A variable maintains a shared, persistent state manipulated by a program. If one uses this function then it will create
1 min read
Difference between $var and $$var in PHP
In PHP, $var is used to store the value of the variable like Integer, String, boolean, character. $var is a variable and $$var stores the value of the variable inside it. $var: Syntax: $variable = value;The $variable is the variable nameThe value is the initial value of the variable. Example 1: This
2 min read
Difference between registering a component locally and globally
This article explores the contrast between locally and globally registering components in React JS, highlighting the distinction in component scope and usage within the application. Table of Content Registering a component locallyRegistering a component GloballyDifference between Local and Global Co
4 min read
Difference between GET and POST request in Vanilla JavaScript
In this article, we will learn about the GET & POST request method in vanilla Javascript, & will also understand these 2 methods through the examples. GET and POST is two different types of HTTP request methods. HTTP protocol supports many methods to transfer data from the server or perform
3 min read
Difference Between Local Storage, Session Storage And Cookies
The HTTP protocol is one of the most important protocols for smooth communication between the server and the client. The main disadvantage of the HTTP protocol is that it is a stateless protocol, which means it does not track any kind of response or request by the server or the client. So, to resolv
6 min read
Difference between Postman vs Paw vs Insomnia
Selecting an appropriate tool for API creation and testing is essential to ensuring efficiency, clarity, and productivity in software projects. With their distinct features, functionalities, and user experiences, Postman, Paw, and Insomnia are three well-liked solutions on the market. Table of Conte
7 min read
Explain the concept of local variables in Postman.
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
2 min read