Site icon QATechTools

Understanding scope and environments in Postman

Environments in Postman

Environments allow you to run requests and collections against different data sets. For example, you could have an environment for development, one for testing, and another for production. You can use variables to pass data between requests and tests, for example if you are chaining requests using a collection.

Environments in Postman are key-value pairs of variables. Each variable name represents its key, so referencing the variable name allows you to access its value.

To create an environment, use New > Environment, or the Manage environments button in the top right of Postman, and click Add. Give your environment a name , such as “Testing”—you can add variables at creation or later, by editing the environment.

To select the environment to run your requests within, use the drop-down at the top right of the Postman app.

Your requests will run with the data variables listed in the environment you have selected.

You can duplicate, delete, download / import environment JSON, and share environments with collaborators in Manage Environments. Sharing environments allows you to let other people run your requests against the same data sets.

Variable scopes

Postman supports the following variable scopes:

If a variable with the same name is declared in two different scopes, the value stored in the variable with narrowest scope will be used—for example if there is a global and a local variable both named username, the local value will be used when the request runs.

Choosing variables

Variable scopes are suited to different tasks in Postman:

Exit mobile version