← API Testing with Postman learning path
API Testing with Postman · Module 4 of 10

Variables and environments

Reuse values across requests and environments.

📖 Key ideas

  1. Variables: {{baseUrl}}, {{token}}.
  2. Scopes: global, collection, environment, local, data.
  3. Environments switch between dev, staging and production.
  4. Set variables in scripts: pm.environment.set("token", value).
  5. Initial vs current values: current values stay local.
💡 Real-life example: Environments are SIM cards: same phone (collection), different networks (dev, staging, prod).
VariableReusable value like {{baseUrl}}
EnvironmentSet of variables for a stage
pm.environment.setSets an environment variable in scripts
ScopeWhere a variable applies