Group sets of variables in Postman using environments

In Postman, an environment is a set of one or more variables that you can reference when sending requests or writing test 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.

Contents

Create an environment

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.

To create a new environment, do the following:

  1. Select Environments in the sidebar and select +.

    Create new environment
  2. Enter a name for your new environment.

  3. Add any variables you want to the environment. You can also add variables later. Learn more about adding environment variables.

  4. Select Save icon Save to save any environment variables you added.

  5. 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.

    Environment selector

You can turn on autosave to automatically save your changes to collections, requests, and environments. Learn more about autosave.

Add environment variables

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. If the value includes sensitive data, such as a password or key, you can mask the value by selecting the secret variable type.
  • 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:

  1. Select Environments in the sidebar and select an environment.

  2. To add a new variable, select the bottom row of the table and enter a Variable name.

    Environment editor
  3. 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.

  4. 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.

  5. When you're done adding environment variables, select Save icon Save.

Switch between environments

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.

Environment selector

You can also make an environment active by selecting Environments in the sidebar. Select the set active icon Set active icon next to an environment to make it the active environment.

Active environment

To check a variable's value at a glance, select the environment quick look icon Environment quick look icon next to the environment selector. The environment quick look lists the initial and current values for all variables in the active environment.

Environment quick look

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.

Use variables in requests and scripts

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.

Environment variable reference

You can access current environment variable values in your Pre-request Script and Tests code 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.

Edit an environment

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 More actions icon and select Duplicate.

  • To delete an environment, select the more actions icon More actions icon and select Delete. Deleting an environment also deletes all variables in the environment.

Next steps

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