#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
Postman

Postman Environment and Global Variables

Environment Variables

Scoped to a specific Environment (e.g., "QA" or "Production"), these variables let the same request adapt automatically depending on which environment is currently active.

Global Variables

Available across all Collections and Environments in a Postman workspace, useful for values that should stay constant no matter which environment is selected.

Using Variables in Requests

Variables are referenced with double curly braces, e.g. {{base_url}}/users/{{user_id}}, keeping requests clean, reusable, and easy to maintain.

Variable Scopes and Which Value Wins

Postman supports several scopes, and when the same name exists in more than one, the narrowest scope is used. From broadest to narrowest the order is: global, collection, environment, data (from a data file in a run), and local (set inside a script for one request). So if base_url exists as a global and in the active environment, the environment value is used.

ScopeVisible toTypical use
GlobalEvery request in the workspaceShared helper values, rarely secrets
CollectionRequests inside one collectionAPI version, common paths
EnvironmentRequests while that environment is selectedBase URLs, test accounts per QA, staging, production
DataOne iteration of a Collection Runner or Newman runRows of test data
LocalThe current request execution onlyTemporary values in scripts

Each variable also has an initial value, which is shared when you sync or export, and a current value, which stays on your machine. Put real tokens and passwords only in the current value, or use Postman's secret type and vault features, so they are not shared with your team by accident.

Worked Example: Reusing a Login Token

Create two environments, QA and Staging, each with base_url, username and password. Then add a login request with this script in its post-response (Tests) tab:

const body = pm.response.json();
pm.test("Login succeeded", () => {
    pm.response.to.have.status(200);
});
pm.environment.set("auth_token", body.token);

Every other request in the collection sets its Authorization header to Bearer {{auth_token}}. Switch the environment dropdown from QA to Staging, run the login again, and all requests now talk to the other server with a fresh token, without editing a single URL.

Other useful script methods include pm.globals.set(), pm.collectionVariables.set(), pm.variables.get() (which reads the value that wins by precedence) and pm.environment.unset() for cleanup.

Mistakes Testers Commonly Make

  • Running destructive tests while the production environment is still selected. Name environments clearly and check the dropdown before sending.
  • Storing the same variable in global and environment scope, then wondering why a change has no effect.
  • Saving secrets in the initial value, which gets shared with the workspace.
  • Hard-coding a URL in one request, so it ignores the environment switch.

Quick Setup Checklist

  • One environment per server, with identical variable names in each.
  • Globals kept to a minimum.
  • Tokens set by script, not pasted manually.
  • Unresolved variables show in red in the URL bar; fix them before running a suite.

Ready to master real-world software testing?

Learn manual and automation testing hands-on with mentor-led sessions.

Explore Course