</>

Technology

Postman

Difficulty

Beginner

Interview Question

What are Environments in Postman and how do you use them?

Answer

Environments in Postman

An Environment in Postman is a set of key-value variables that let you quickly switch between different configurations (dev, staging, production) without changing your requests.

Creating an Environment

  1. Click Environments in the left sidebar
  2. Click + to create a new environment
  3. Name it (e.g., "Production", "Staging", "Local")
  4. Add variables:
VariableInitial ValueCurrent Value
base_urlhttps://api.production.comhttps://api.production.com
api_keyprod-key-123prod-key-123

Using Environment Variables in Requests

Reference variables with {{variable_name}}:

CODE
URL: {{base_url}}/api/users
Header: Authorization: Bearer {{api_key}}
Body: { "env": "{{environment_name}}" }

Switching Environments

  1. Click the environment dropdown (top-right, next to the eye icon)
  2. Select "Staging" — all {{base_url}} references now point to staging URL
  3. Run your requests — same collection, different config

Types of Variables (Scope)

ScopeOverridesVisibility
GlobalNothingAll environments
EnvironmentCollectionCurrent environment only
CollectionEnvironmentCurrent collection only
LocalAllCurrent request only
Variable priority (highest → lowest): Local > Data > Environment > Collection > Global

Practical Example

JavaScript
// In Tests tab — save token from login response to environment
pm.test("Save auth token", function () {
    const jsonData = pm.response.json();
    pm.environment.set("auth_token", jsonData.token);
});

// In next request
// Authorization: Bearer {{auth_token}}

Environment Secret Variables

  • Mark sensitive values (passwords, tokens) as Secret in Postman
  • Secrets are not synced to Postman cloud for security

Follow AutomateQA

Related Topics