How to Create Environment in Postman: Step-by-Step Guide
To create an environment in Postman, click the
Environments icon in the top right, then select Create Environment. Add variables with names and values, save the environment, and select it to use those variables in your API requests.Syntax
In Postman, an environment is a set of key-value pairs called variables. You create an environment by defining these variables and saving them under a name. The basic steps are:
- Open the Environments manager.
- Click
Create Environment. - Enter a name for the environment.
- Add variables with
KeyandValue. - Save the environment.
These variables can then be used in requests with the syntax {{variableName}}.
text
Environment Name: MyEnvironment Variables: baseUrl: https://api.example.com apiKey: 12345abcde Usage in request URL: {{baseUrl}}/users?api_key={{apiKey}}
Example
This example shows how to create an environment named TestEnv with two variables, and how to use them in a request URL.
text
1. Click the gear icon (Manage Environments) in the top right of Postman. 2. Click <Create Environment>. 3. Enter TestEnv as the environment name. 4. Add variables: - Key: baseUrl, Value: https://jsonplaceholder.typicode.com - Key: userId, Value: 1 5. Click <Save>. 6. Select TestEnv from the environment dropdown next to the gear icon. 7. In a new request, set the URL to: {{baseUrl}}/posts?userId={{userId}} 8. Send the request to get posts for user 1.
Output
Response: JSON array of posts for userId 1 from https://jsonplaceholder.typicode.com
Common Pitfalls
Common mistakes when creating environments in Postman include:
- Not saving the environment after adding variables.
- Using variable names incorrectly in requests (missing double curly braces
{{}}). - Forgetting to select the environment before sending requests.
- Using variable names that conflict with global or collection variables.
Always double-check variable names and ensure the correct environment is active.
text
Wrong usage: Request URL: https://api.example.com/users?api_key=apiKey Right usage: Request URL: https://api.example.com/users?api_key={{apiKey}}
Quick Reference
| Step | Action |
|---|---|
| 1 | Click gear icon (Manage Environments) |
| 2 | Click Create Environment |
| 3 | Enter environment name |
| 4 | Add variables (Key and Value) |
| 5 | Save environment |
| 6 | Select environment from dropdown |
| 7 | Use variables in requests with {{variableName}} syntax |
Key Takeaways
Create environments in Postman to store reusable variables for API requests.
Always save your environment after adding or editing variables.
Use double curly braces {{variableName}} to reference environment variables in requests.
Select the correct environment before sending requests to apply its variables.
Avoid variable name conflicts by using clear, unique names.