Variables in Postman allow you to store and reuse values dynamically across requests. They help avoid hardcoding values like URLs, tokens, IDs, and credentials. Postman supports Global, Collection, and Local variables.
Variables are accessed using double curly braces syntax:
{{variableName}}
Postman resolves variables based on priority: Local → Data → Environment → Collection → Global
// Using a variable in a request URL
GET {{baseUrl}}/users/{{userId}}
// Setting a collection variable in Tests tab
pm.collectionVariables.set("token","abc123");
Postman replaces {{baseUrl}} and {{userId}} with their current values before sending the request. This makes APIs flexible across environments.
Think of variable scopes as layers. Use the simulator below to understand how Postman decides which value to use when the same variable name exists in different scopes.
Imagine you have a variable named {{apiKey}} defined in three places. Enter values below to see which one "wins".
// Local variable example inside a script
pm.variables.set("tempValue",100);
baseUrl