Site icon Learn Automation

How To Set Postman Environment Variables

Hello Friends, In this post we will see topic related Postman Environment Variables – How to create environment variables, Adding environment variables, Setting environment variables from scripts etc.

What is Environment Variables in Postman?

Environment is a set of key-value pairs in postman and we can use this key-value pair in our postman request.

We can use environments to group related sets of values together and manage access to shared Postman data if you are working as part of a team.

When we work in real time or real world APIs we know that we might have to test APIs on multiple environments and multiple environments have different endpoints, different username and password and different values. So set of values which are vary we can group into environments.

Environment Variables in Postman

Now we will see How to create environment and environment variables in Postman.

It has three steps involved in this process.

  1. Create an environment
  2. Create environment variables
  3. Use environment variables in Postman request

Step 1: How to create an Environment in Postman:

  1. Create a new collection and name it as Collection1.
  2. Add a dummy API and add GET request. In below image you can see I have added collection and inside this created a GET request.

3. Click on View icon which says add the environment.

4. Click on Add link to the environment and create with name Dummy API Environment.

 

Step 2: How to create Environment variables in Postman:

  1. Now in the same window we can add variables in key-value pair.

I have added URL as a Key and their value.

Key: url

Value: https://reqres.in/

Note: When we enter initial value, by default it will copy same into current value.

 

Step 3: How to use Environment variables in Postman:

  1. Select environment from dropdown which have created before.

Now we can access all variables of this environment.

2. Now open collection which was earlier we have created.

And add {{url}} in place of https://reqres.in/api/users?page=2

3. Click on Send.

As of now we have created environment variable url and used it into address bar in our GET request. We can also use this in different Collection. We can see we get same response in response body.

So, if in future URL will change then we just need to open environment variable and change it and it will reflected in every request.


Deleting Environments in Postman

  1. In right hand side we can see Environment Click on this.

 

2. Mouse Hover on your created Environment. We can see (…). Click on it then click on delete link.

 

I hope this tutorial is helpful for you to understand “What is Postman Environment Variables”.

In future I will post What is Global variables in Postman and How to use that.

Please subscribe my blog for latest post in future.

Must Read:

API Testing with Postman

 

Exit mobile version