0 votes
in XML by
What are Variables in Postman?

1 Answer

0 votes
by

Variables in Postman

  • Postman variables work in the same way as that of the programming variables. These are the symbols capable of taking various values. You can store the values in variables and can use it throughout in requests, environments, collections, and scripts.
  • Variables in Postman increase the user's efficiency to work and decrease the errors.

Environment in Postman

A collection of key-value pairs is called an environment. Each name of the variable represents its keys. And referencing the name of the variable allows you to access its value.

It is a set of variables that differentiate among the requests. Such as, we can have an environment for testing, one for development and another for production. We can change the value of the variables to pass the data between requests and tests.

Creating an Environment

To create an environment, follow the following steps:

  • Go to New -> Environment.
     
  • Or you can create an environment from Environment quick look. For that, click on Environment quick look button visible as an eye icon available in the top right corner of the builder section, as shown in the image below.
     

Now select Add.

Variables in Postman

Enter the name of the Environment and click on Add.

Variables in Postman

We can also download, share, delete, duplicate, or import the environment.

Variables in Postman

Sharing an environment will help you to run your requests against the same set of data.

Environment Variable in Postman

The postman variable is similar to the programming language variable. As we know, a variable is an entity, which stores value. You can change the value of the variable. In Postman, a variable is a set of key-value pairs. Here the key is the variable and value is the value of the variable.

Creating an Environment Variable in Postman

To create an environment variable follow the following steps:

  • Go to Environment quick look button visible as an eye icon available in the top right corner of the builder section.
    Variables in Postman
  • Select the Edit option.
    Variables in Postman
  • Enter the below mentioned key-value pairs in which Key = url and Initial Value = http://restapi.demoqa.com
    Variables in Postman

Then select the Update button and close the Manage Environment window. Now you have an environment variable with the name 'url', and the value of the variable is the http://restapi.demoqa.com.

Using an Environment Variable in Postman

  • Select the environment from the drop-down. Now we can access the entire available variable in the environment.
    Variables in Postman
  • In the address bar or we can say URL text field enter the following url: {{url}}/utilities/weatherfull/city/Bengaluru
    Variables in Postman
  • Click on send. You will get the following response:
    Variables in Postman

So, the environment is created with a variable named "url". This means we can now use the variable instead of the actual URL.

Global Variables in Postman

Here we will see how to create global variables. Unlike the environment variable, in the case of global variables, we don't need to create an environment first.

Creating a Global Variable in Postman

  • Open the Postman app and click on Environment quick look button visible as an eye icon available in the top right corner of the builder section, as shown in the image below.
    Variables in Postman
  • Now select Edit option as shown in the image below available next to Globals.
    Variables in Postman
  • Enter the below mentioned key-value pairs in which Key = url and Initial Value = http://restapi.demoqa.com
    Variables in Postman
  • Select the save button and close the Manage Environments Here your global variable is created with the name 'url'.

Using a Global Variable in Postman

Select the No Environment from the drop-down of Postman, from the top right corner of Postman.

Related questions

0 votes
asked Sep 16, 2020 in XML by GeorgeBell
0 votes
asked Sep 16, 2020 in XML by GeorgeBell
0 votes
0 votes
asked Sep 16, 2020 in XML by GeorgeBell
+1 vote
asked May 20, 2021 in POSTMAN by sharadyadav1986
...