← API Testing with Postman learning pathAPI Testing with Postman · Module 4 of 10
Variables and environments
Reuse values across requests and environments.
📖 Key ideas
- Variables: {{baseUrl}}, {{token}}.
- Scopes: global, collection, environment, local, data.
- Environments switch between dev, staging and production.
- Set variables in scripts: pm.environment.set("token", value).
- 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