Postman Variables & Environment Management
Variables and environments are important features in Postman that help create reusable, dynamic, and maintainable API requests. Instead of hardcoding values such as URLs, tokens, usernames, or IDs, Postman allows storing these values in variables and using them across requests and collections. Variables improve automation, reduce manual work, and make it easy to switch between different environments like Development, Testing, and Production.
1. Variables Introduction
Variables are placeholders used to store reusable values in Postman. They allow users to avoid repeating the same information in multiple requests.
Variables are written using double curly braces.
Example
{{base_url}}
Instead of manually writing:
https://api.example.com
you can store it in a variable and reuse it everywhere.
Benefits of Variables
● Reusability
● Easy maintenance
● Faster testing
● Dynamic request handling
● Environment switching
2. Global Variables
Global Variables are accessible throughout the entire Postman workspace. Any collection or request can use them.
These variables are useful for storing common values shared across multiple projects.
Example
{{company_name}}
Common Uses
Company name
Shared URLs
Global settings
Features
● Available everywhere
● Workspace-level scope
● Easy to access
● Limitation
Changes affect all collections using the variable.
3. Local Variables
Local Variables exist only during a single request or script execution. They are temporary variables and disappear after execution completes.
Example
pm.variables.set('temp_id', 101);
Features
● Temporary storage
● Limited scope
● Faster execution
● Request-specific
Use Cases
● Temporary calculations
● Session-based values
● Dynamic processing
4. Collection Variables
Collection Variables are accessible only inside a specific collection. They help organize variables at the project level.
Example
{{auth_token}}
Features
● Collection-specific
● Shared across requests in collection
● Easier project organization
Use Cases
● Authentication tokens
● Project-specific URLs
● Shared request data
5. Environment Variables
Environment Variables store different values for different environments such as Development, QA, Staging, and Production.
Example
{{base_url}}
The value changes depending on the selected environment.
Example Environments
Environment URL
Development dev.api.com
Testing test.api.com
Production api.com
Benefits
● Easy environment switching
● Reduced manual editing
● Better testing workflow
Common Usage
● API URLs
● Tokens
● Database configurations
6. Dynamic Variables
Dynamic Variables are automatically generated by Postman during request execution. These variables help create random test data.
Features
● Auto-generated values
● Random data generation
● Useful for automation testing
Use Cases
● Random user registration
● Unique email generation
● Timestamp testing
7. Setting Variables
Variables can be created and updated manually or through scripts.
Methods to Set Variables
● Using Postman UI
● Using Pre-request Scripts
● Using Test Scripts
Example
pm.environment.set('token', 'abc123');
This stores the token in the environment variable.
Purpose
● Save API responses
● Reuse tokens
● Dynamic request handling
8. Using Variables in Requests
Variables can be used in different parts of API requests.
Areas Where Variables Are Used
● URL
● Headers
● Authorization
● Request Body
Example URL
{{base_url}}/users
Example Header
Authorization: Bearer {{token}}
Advantages
● Cleaner requests
● Faster updates
● Better maintainability
9. Secret Variables
Secret Variables are used to securely store sensitive information.
Examples
● Passwords
● API Keys
● Tokens
● Client Secrets
Features
● Hidden values
● Improved security
● Prevent accidental exposure
Example
{{api_secret}}
Best Practices
● Never hardcode secrets
● Use secret variables for credentials
● Avoid sharing sensitive data publicly
10. Managing Multiple Environments
Postman allows users to create and switch between multiple environments easily.
Example Workflow
A developer may test APIs in:
● Development Environment
● QA Environment
● Production Environment
Instead of changing URLs manually, users simply switch environments.
Example
Development → Production
Benefits
● Faster API testing
● Reduced human errors
● Better project organization
● Simplified deployment testing
Variables & Environment Management — Quick Table
Type Scope Lifetime Example Best Use
-----------------------------------------------------------------------------------------------------------
Global Variables Entire workspace Until deleted {{api_version}} Shared constants across all collections
Local Variables Current request/run Temporary variables.set('id',101) Runtime/temp values
Collection Variables Specific collection Until changed {{base_url}} Collection-level configs
Environment Variables Selected environment Until changed {{token}} Dev/QA/Prod configurations
Dynamic Variables Auto-generated Per request {{doller symbol+guid}} Random test data
Secret Variables Hidden sensitive values Until changed API keys, passwords Secure credentials
Variable Scope Priority in Postman
Priority Variable Scope Description -------------------------------------------------------------------- 1 (Highest) Local Temporary variables created during request execution 2 Data Variables from external data files (CSV/JSON) 3 Environment Variables specific to selected environment 4 Collection Variables available within a collection 5 (Lowest) Global Variables available across entire workspace
Order Representation
Local ↓ Data ↓ Environment ↓ Collection ↓ Global Higher-priority variables override lower-priority variables if they have the same name.
Example
Suppose all scopes contain:
token = different_value
Postman uses the value from the highest priority scope available.
Example:
Scope Value
Global global123
Collection collection123
Environment env123
Result:
{{token}} → env123
because Environment has higher priority than Collection and Global.