What is an Environment Variable in Postman?

A variable is used to store and add parameters in a request, Collection, scripts and so on. An Environment in Postman comprises a key-value pair. The key in an Environment is known as the Environment variable.

An Environment variable has a local scope which means a variable defined within an Environment can be accessed in the same Environment in which it is created. In case we try to access that variable outside the Environment in which it is created, we shall encounter errors.

To create an Environment variable we have to follow the below steps −

Step 1 − Click on the New menu and then click on the Environment link.

Step 2 − The MANAGE ENVIRONMENTS window shall be opened. Give an Environment name – ENV1. Add a variable u for the VARIABLE field and https://jsonplaceholder.typicode.com/users for the INITIAL VALUE.

Step 3 − The Environment – ENVI gets added as an item in the No Environment dropdown.

Step 4 − Choose the Environment ENV1 and add {{u}} in the address bar. To use an Environment variable in a request, we have it enclose it with double curly braces {{<Environment variable name>}}.

Step 5 − Click on Send. Here, we have used the Environment variable – {{u}} instead of the actual endpoint in the address bar.