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
- ✓Click Environments in the left sidebar
- ✓Click + to create a new environment
- ✓Name it (e.g., "Production", "Staging", "Local")
- ✓Add variables:
| Variable | Initial Value | Current Value |
|---|---|---|
base_url | https://api.production.com | https://api.production.com |
api_key | prod-key-123 | prod-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
- ✓Click the environment dropdown (top-right, next to the eye icon)
- ✓Select "Staging" — all
{{base_url}}references now point to staging URL - ✓Run your requests — same collection, different config
Types of Variables (Scope)
| Scope | Overrides | Visibility |
|---|---|---|
| Global | Nothing | All environments |
| Environment | Collection | Current environment only |
| Collection | Environment | Current collection only |
| Local | All | Current 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
