Edit and set environment variables in Postman

An environment is a group of variables whose values you can change depending on your work context in Postman. After you create an environment, you can add new environment variables, change initial or current values, or delete variables. You can also set environment values using scripts, and you can persist variable values to make them available to your team.

Edit environment variables

You can edit environment variables by adding new variables, changing a variable's type and values, or deleting variables.

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 environment variables, select Environments in the sidebar and select an environment. From here you can take the following actions:

  • To filter the list of environment variables by name, enter text in the Filter variables box.
  • To sort the list of environment variables, select a column header. You can toggle between ascending and descending order. To manually sort the list, clear the sort order if needed by selecting a column header, then drag rows using the handles.
  • To add a new environment variable, select Add new variable in the bottom row of the table.
  • To delete an environment variable, hover over a variable and select the delete icon Delete icon.
  • To make an environment variable unavailable without deleting it, clear the checkbox next to the variable. Any references to the variable will be unresolved. To make the variable available again, select the checkbox.
  • Select Save icon Save to save any changes you've made.
Add environment

To edit an environment variable, select the variable and change any of the following:

  • Variable - The name of the variable. Use the name to reference the variable in requests and scripts.

  • Type - If you select default, the variable value is visible in plain text. If you select secret, the variable value is masked. Learn more about variable types.

    To show or hide a secret variable, hover over the variable and select the eye icon Unmask variable icon.

  • 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. 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 editing environment variables, select Save icon Save to save your changes.

Edit variables from the environment quick look

You can edit the current value for variables in the active environment from the environment quick look. Select the environment quick look icon Environment quick look icon next to the environment selector. Select the edit icon Edit icon next to a variable, then enter a new current value.

Using the environment quick look

Set environment variables from scripts

You can change the values of environment variables from your Pre-request Script and Tests scripts. Use the pm.environment method to set an environment variable in the active environment:

pm.environment.set("variable_key", "variable_value");

If you use scripts to set values for environment variables, these values will be reflected in all requests that reference the variables. For example, you can use environments in conjunction with the collection runner and monitors to use updated values for a series of requests throughout a run and after the run completes.

To create new environment variables from a script, you must have Editor access to the environment. If you update or unset a value in a script when you have Viewer access, that change will be visible to you but won't be shared with other team members. Learn more about managing environment roles.

Persist environment variables

An environment variable's current value is used in your local instance of Postman and isn't synced to your Postman account or shared with your team. If you want to sync an environment variable's current value with your account or share it with team members, you can persist the variable.

When you persist a variable, the variable's initial (shared) value is set to the current (local) value. The initial value is then synced to your Postman account, and anyone who has access to the environment can view the new initial value. If a variable's initial value has sensitive data, make sure to choose the secret variable type if you don't want to expose the value when sharing or publishing the environment.

To persist a variable, you must have Editor access to the environment. Learn more about managing environment roles.

To persist an environment variable, do the following:

  1. Select Environments in the sidebar and select an environment.
  2. Select the more actions icon More actions icon next to a variable and select Persist. The current value is copied to the initial value.
  3. Select Save icon Save. The new initial value is synced to your workspace and is available to anyone with access to the environment.

At any time you can reset a variable's current (local) value with the initial (shared) value synced to your workspace. Select the more actions icon More actions icon next to a variable and select Reset. The current value is replaced by the initial value. Select Save icon Save to save the change.

You can persist or reset all variable values in the environment at once. Select the more actions icon More actions icon in the column header, then select Persist All or Reset All.

Last modified: 2023/11/09