Postman Environments and Variables
Every professional API setup has at least three versions: development, testing, and production. Each version uses a different base URL and often a different API key. Environments in Postman let you switch between these setups instantly without editing every request manually.
The Problem Variables Solve
Suppose you are testing a payments API. Your base URL changes depending on where you are in the project:
Development: https://dev.payments-api.com
Testing: https://staging.payments-api.com
Production: https://api.payments-api.com
Without variables, you update every single request URL each time you switch environments. With variables, you change one value and every request updates automatically.
How Variables Work – The Template Diagram
Variable defined in Environment:
baseUrl = https://dev.payments-api.com
Request URL using the variable:
{{baseUrl}}/users/1
What Postman sends:
https://dev.payments-api.com/users/1
Switch Environment:
baseUrl = https://api.payments-api.com
What Postman sends now:
https://api.payments-api.com/users/1
The double curly braces {{variableName}} are Postman's syntax for inserting a variable value.
Types of Variables in Postman
| Variable Type | Scope | Best Used For |
|---|---|---|
| Global | All workspaces and environments | Values that never change across any context |
| Environment | One environment only | Base URL, API keys per environment |
| Collection | All requests in one collection | Shared values for one project |
| Local | Current request only | Temporary values set in scripts |
| Data | One Collection Runner run | Values loaded from a CSV or JSON data file |
When multiple variable types have the same name, Postman uses this priority: Local beats Data, which beats Environment, which beats Collection, which beats Global.
Create an Environment
- Click the Environments tab in the left sidebar
- Click the + button to create a new environment
- Name it Development
- Add variables by filling in the table:
| Variable Name | Initial Value | Current Value |
|---|---|---|
| baseUrl | https://jsonplaceholder.typicode.com | https://jsonplaceholder.typicode.com |
| userId | 1 | 1 |
- Click Save
Repeat this process to create a Staging environment with a different base URL.
Initial Value vs Current Value
- Initial Value — saved with the environment and visible to teammates when you share the environment. Do not put real passwords or secret API keys here.
- Current Value — only visible to you locally. Safe to put sensitive values here. This value overrides the initial value during your current session.
Use Variables in a Request
- Select your Development environment from the dropdown in the top-right corner of Postman
- Open a request and type {{baseUrl}}/users/{{userId}} in the URL bar
- Click Send
Postman replaces {{baseUrl}} with https://jsonplaceholder.typicode.com and {{userId}} with 1 before sending. The URL bar shows the variables highlighted in orange so you can see where they appear.
Set Variables Dynamically from a Script
You can set variable values automatically from a test script. A common use case is saving an access token after a login request.
// In the Scripts tab → Post-response section:
const response = pm.response.json();
pm.environment.set("accessToken", response.token);
After the login request runs, the token is saved to the accessToken variable in your environment. Every subsequent request that uses {{accessToken}} picks up the saved value automatically.
View and Edit Active Variables
Click the eye icon in the top-right corner of Postman (next to the environment dropdown) to open a quick view of all current variable values. You can edit values directly from this panel without opening the full environment editor.
Share an Environment
Export an environment to a JSON file the same way you export collections:
- Click the three-dot menu on the environment in the sidebar
- Select Export
- Save the JSON file
Share this file with teammates. They import it into their Postman and have the same environment setup immediately. Remember: share initial values, never current values that contain real secrets.
Summary
Environments hold variables that change between development, staging, and production setups. You use {{variableName}} syntax anywhere in Postman — URLs, headers, body, scripts — to insert variable values. Switching environments updates all requests instantly. Scripts can set variables dynamically so that values like login tokens save and reuse themselves automatically.
