In Postman, an environment is a set of one or more variables that you can reference when sending requests, writing pre-request scripts, or writing post-response scripts. You can create environments for the different types of work you do in Postman. When you switch between environments, all of the variables in your requests and scripts will use the values from the current environment. This is helpful if you need to use different values in your requests depending on the context, for example, if you're sending a request to a test server or a production server.
Environments can also help you to collaborate on Postman data if you're working as part of a team. You can use environments to share variables and manage the visibility of sensitive data such as API keys, passwords, or tokens. Learn more about working with environments as a team in Postman.
Create a new environment when you want to be able to change the values of variables depending on your work context in Postman, or to share values with other team members. You can also create a new environment from the environment selector, making it the active environment.
To create a new environment, do the following:
Select Environments in the sidebar and select +. You can also select the environment selector at the top right of the workbench and select +.
Enter a name for your new environment.
Add any variables you want to the environment. You can also add variables later. Learn more about adding environment variables.
Select Save to save any environment variables you added.
To use the new environment, select it from the environment selector at the top right of the workbench. This makes it the active environment and sets all variables to the values specified in the environment. Learn more about switching between environments.
If you created the new environment from the environment selector, the new environment should already be the active environment.
You can turn on autosave to automatically save your changes to collections, requests, and environments. Learn more about autosave.
When you add a variable to an environment, you can specify the Initial value (shared) and the Current value (local) for the variable:
Initial value (shared) - This value is synced to your account using Postman's cloud servers. It's shared with any collaborators who have access to the environment. It's also made public when publishing an environment along with a collection.
It's recommended that you use your Postman Vault to store sensitive data, such as API keys, as vault secrets. Only you can access and use values associated with your vault secrets, and vault secrets aren't synced to the Postman cloud. If you want to share sensitive data with collaborators, you can store it in an environment as a secret type variable.
Current value (local) - This value is used when sending requests in your local instance of Postman. It's never synced to your account or shared with your team unless you choose to persist it.
To add variables to an environment, do the following:
Select Environments in the sidebar and select an environment.
To add a new variable, select the bottom row of the table and enter a Variable name.
Select a variable Type. If you select default the variable value is visible in plain text. If you select secret the variable value is masked.
If a variable's initial value has sensitive data, select the secret variable type to prevent exposing the value when sharing or publishing the environment. Learn more about variable types.
Enter the Initial value and Current value for the variable. Keep in mind that the initial value is shared with anyone who has access to the environment, and the initial value is made public if you publish the environment along with a collection.
If you leave the current value blank, the initial value is copied to the current value when you save the environment.
When you're done adding environment variables, select Save.
You can also add a variable with a current value to an environment from a Postman element, such as a request. Use double curly braces to reference a variable that doesn't exist or isn't accessible from the element. Hover over the reference to the variable and select Enter value. Enter a current value, select the Add to dropdown list, then select the environment scope. Make sure the environment you want to add the variable to is selected in the environment selector. Learn more about adding variables to a scope.
Postman displays the active environment in the environment selector, located in the top right of the workbench. When you send a request or run a script, Postman uses the current values for all variables in the active environment. To make another environment active, select it from the environment selector.
You can select + in the environment selector to create a new environment and make it the active environment.
You can also make an environment active by selecting Environments in the sidebar. Select the set active icon next to an environment to make it the active environment.
To check a variable's current value, select Variables in the workbench to open the variables pane. The variables pane lists the current values for all variables in the active environment.
If you want to make variables available regardless of which environment is active, use global variables. The quick look lists any global variables you have declared or that are shared in your workspace.
To use an environment variable in a request, reference it by name surrounded with double curly braces:
{{base_url}}
You can reference environment variables in request URLs, parameters, headers, and body data. Hover over a variable reference to view its current value.
You can access current environment variable values in your Pre-request and Post-response scripts using the pm.environment.get
method:
pm.environment.get("variable_name");
If more than one variable with the same name is available to a request, Postman will use the value from the variable with the narrowest scope. Therefore, if you have an environment variable with the same name as a collection or global variable, Postman will use the environment variable. However, local and data variable values will supersede environment values. The value of any overridden variables will display in strikethrough format.
Learn more about editing and setting environment variables in Postman.
If you're working with environments as part of a team, you must have the Editor role to edit the environment or change initial values for variables. Learn more about managing environment roles.
To edit an environment, select Environments in the sidebar and select an environment. From here you can take the following actions:
To rename an environment, select the environment's name and enter a new name.
To duplicate an environment, select the more actions icon and select Duplicate.
To delete an environment, select the more actions icon and select Delete. Deleting an environment also deletes all variables in the environment.
Environments enable you to share data in Postman and collaborate with your team. Here are some more resources to help you use environments with your team:
Last modified: 2023/11/09
Additional resources
Videos
Blog posts
Case Studies