How to Use Variables in Postman Request Body Easily
In Postman, you can use variables in the request body by enclosing the variable name in double curly braces like
{{variableName}}. These variables can be defined in environments, globals, or collections and Postman replaces them with their values when sending the request.Syntax
To use a variable in the Postman request body, write the variable name inside double curly braces {{variableName}}. Postman will replace this placeholder with the actual value of the variable when the request runs.
Variables can come from different scopes like environment, global, or collection variables.
json
{
"username": "{{userName}}",
"password": "{{userPassword}}"
}Example
This example shows how to use environment variables in the JSON body of a POST request. The variables userName and userPassword are replaced by their values defined in the environment.
json
{
"username": "{{userName}}",
"password": "{{userPassword}}"
}Output
Request body sent with actual username and password values replacing the variables.
Common Pitfalls
- Not defining the variable in any scope causes Postman to send the variable name as is, resulting in failed requests.
- Using single curly braces
{variableName}instead of double{{variableName}}will not work. - Variables are case-sensitive; mismatched names cause unresolved variables.
- For raw JSON bodies, ensure the variable is inside quotes if the value is a string.
json
{
"username": "{userName}"
}
{
"username": "{{userName}}"
}Quick Reference
| Step | Description |
|---|---|
| 1 | Define variables in environment, global, or collection. |
| 2 | Use variables in body with double curly braces: {{variableName}}. |
| 3 | Ensure variable names match exactly and are defined. |
| 4 | For JSON strings, wrap variables in quotes. |
| 5 | Send request; Postman replaces variables with values. |
Key Takeaways
Use double curly braces {{variableName}} to insert variables in Postman request bodies.
Always define variables in an environment, global, or collection before using them.
Variable names are case-sensitive and must match exactly to be replaced.
Wrap variables in quotes in JSON bodies if the value is a string.
If a variable is undefined, Postman sends the placeholder text, causing errors.