Variables let you reuse values easily in your tests without typing them again and again.
0
0
Variable syntax ({{variable}}) in Postman
Introduction
When you want to use the same API key in many requests.
When you need to change the server URL quickly for different environments.
When you want to store a user ID and use it in multiple test steps.
When you want to keep your tests clean and easy to update.
When you want to share common data across different requests.
Syntax
Postman
{{variable}}Use double curly braces around the variable name.
Postman replaces {{variable}} with its current value when running requests.
Examples
This URL uses the variable
userId to get a specific user.Postman
GET https://api.example.com/users/{{userId}}This header uses the variable
authToken for authentication.Postman
Authorization: Bearer {{authToken}}Variables
userName and userAge fill in the request body dynamically.Postman
body: { "name": "{{userName}}", "age": {{userAge}} }Sample Program
This test uses the variable userId to get user details. Changing the variable changes the user fetched without editing the request URL.
Postman
1. Set variable 'userId' to '12345' in Postman environment. 2. Send GET request to https://api.example.com/users/{{userId}} 3. Postman replaces {{userId}} with '12345' and sends GET https://api.example.com/users/12345 4. Check response status is 200 5. Assert response body contains user with id 12345
OutputSuccess
Important Notes
Variables can be set at different levels: global, environment, collection, or local.
If a variable is not found, Postman sends the request with the {{variable}} text as is, which may cause errors.
Use clear and meaningful variable names to avoid confusion.
Summary
Variables use {{variable}} syntax to insert values dynamically.
This helps reuse data and makes tests easier to maintain.
Always set variables before using them in requests.