Variables enable you to store and reuse values in Postman. By storing a value as a variable, you can reference it throughout your collections, environments, requests, and scripts. Variables help you work efficiently, collaborate with teammates, and set up dynamic workflows.
A variable is a symbolic representation of data that enables you to access a value without having to enter it manually wherever you need it. This can be useful if you're using the same values in multiple places. Variables make your requests more flexible and readable by abstracting the detail away.
For example, if you have the same URL in more than one request, but the URL might change, you can store it in a "base_url" variable. Then, use "{{base_url}}" to reference the variable in your requests. If the URL changes, you can change the variable value and it'll be reflected throughout your collection wherever you've used the variable name.
The same principle applies to any part of your request where data is repeated. Whatever value is stored in the variable will be included wherever you've referenced the variable when your requests run. If the variable value is https://postman-echo.com
and the request uses the {{base_url}}/get
URL, then Postman sends the request to https://postman-echo.com/get
.
Variables in Postman are key-value pairs. Each variable name represents its key, so referencing the variable name enables you to access its value. You can use variables to pass data between requests and tests. For example, if you are chaining requests in a collection.
Use your Postman Vault to store sensitive data as vault secrets and reuse them in your local instance of Postman. Only you can access and use values associated with your vault secrets and secrets aren't synced to the Postman cloud.
Use environments to group sets of variables together and share them with collaborators. For example, if you use one set of config details for your production server and another for testing. See Group sets of variables in Postman using environments for more on how you can incorporate environments into your team workflows.
Postman supports variables at different scopes, allowing you to tailor your processing to a variety of development, testing, and collaboration tasks. Scopes in Postman relate to the different contexts that your requests run in, and different variable scopes are suited to different tasks.
You can create a variable without a variable scope if it isn't meant to hold a default value. You can also create a variable without a scope to try out the value before adding it to a scope. Learn more about creating variables without a scope.
In order from broadest to narrowest, these scopes are: global, collection, environment, data, and local.
If a variable with the same name is declared in two different scopes, the value stored in the variable with narrowest scope will be used. For example, if there is a "username" global variable and a "username" local variable, the local value is used when the request runs.
Postman stores variables as strings. If you store objects or arrays, remember to
JSON.stringify()
them before storing, andJSON.parse()
them when you retrieve them.
By default, collection, environment, and global variable values are only available locally in your instance of Postman. The local value is used when sending requests, and it isn't synced to the Postman cloud. Update your local value as you'd like, without sharing it with your teammates. Learn how to define a local value for your variables.
If you have Editor access to the element, you can share a variable's value, syncing it's value to the Postman cloud. Share a variable's value to provide your teammates with a default value they can use to begin making requests to your API. Your teammates can continue to update their local value without sharing it. They can also reset their local value back to the shared value at any time.
Some Postman features that run on the Postman cloud also use the shared value when sending requests. These features include scheduled collection runs, monitors, the Postman CLI, and Newman.
If you're more familiar with current and initial values, learn more about the previous way of defining variables.
Postman no longer supports maintaining multiple independent values for your collection, environment, and global variables. Previously, you could provide a current value (local) and initial value (shared) for your variables and update them separately.
Initial and current values are supported in the Postman VS Code extension. Learn more about variables in the VS Code extension.
With this change, you only need to provide a single value for your variables that's local by default (previously the current value). Learn how to define a local value for your variables.
You can choose to share a variable's value with your teammates (previously the initial value), based on the local value at the time of sharing. You can continue to update and use your local value without sharing it. Updates to your local value are only shared with your teammates if you intentionally choose to share the new value.
Variable values are local by default and only available to you in your instance of Postman. These values aren't synced to the Postman cloud. Once you've defined a local value, you can optionally share variable values, syncing the value to the Postman cloud.
Remember to delete variables you're no longer using.
To define variables at any scope in the request builder, do the following:
Select the data you need, for example in the address, parameters, headers, or body.
Right-click the selection and click Set as variable.
Click Set as new variable.
Enter a Name, confirm the Value is correct, and select a Scope. Then click Set Variable.
You can also define variables in the following ways:
Learn more about variable scopes in Postman.
You can also learn how to define variables from the VS Code extension.
Variables without a variable scope are useful for trying out the value before adding the variable to a scope. This is also useful for sending data with requests that isn't meant to hold a default value. For example, a variable without a scope might send user-specific information that changes each time you send the request. Variables without a scope also enable you to create a placeholder variable to share with your API consumers, without having to define the variable at a specific scope.
In the request builder, you can create a variable without adding it to a variable scope. The value you enter for this variable is stored locally and is only available in the request it's set in. When you click Variables, the variable isn't associated with a scope (highlighted by color) in the variables pane under Variables in request.
To create a variable from the request builder, use double curly braces ("{{" and "}}") to reference a variable that doesn't exist or isn't available from the request. For example, enter "{{username}}" to create a username variable that doesn't have a scope.
To set a value for a variable without a scope, hover over it, click the text box, then enter a value. You can also click Variables in the workbench to open the variables pane. Click Enter value next to the variable, then enter a value.
You can use
pm.variables.get(variableName)
to access variables without a scope in scripts. Learn more about using variables in scripts.
Values for variables without a scope are stored locally in a request until you close its tab or sign out of Postman. When you open the request again, the variable's value will be empty. If you'd like to store and reuse the value in your requests, you can add the variable and its value to a scope.
You can also create a vault secret without adding it to your Postman Vault. Open your Postman Vault, then use the "{{vault:secret-name}}" syntax. When you're ready, you can add the vault secret to your Postman Vault. Learn how to create and add a vault secret from the request builder.
From a Postman element, such as a request or collection, you can create a variable and add it to a specific variable scope to reuse it across your requests. You can also add a variable without a scope to a specific variable scope in your team. From the element, you can add a value that's stored locally for the variable.
You need Editor access to an environment or collection to add variables to it.
Use double curly braces ("{{" and "}}") to reference a variable that doesn't exist or isn't available from the element. Hover over the reference to the variable, click the text box, then enter a value if you haven't already. Select the Add to dropdown list, then select the scope you'd like to add the variable to.
You can define variables at any scope from the Authorization tab. Select the Auth Type dropdown list, select an authorization, then enter a value in a field that holds sensitive data, such as a password or token. Hover over Sensitive value, click Set as Variable, enter a name for the variable, then select the scope you'd like to add it to.
You can also click Variables in the workbench to view the variables and vault secrets used in your request. Click the text box, enter a value for the variable without a scope, click
Add to, then select the scope you'd like to add it to.
You can also choose to add sensitive data as a vault secret in your Postman Vault. To add it as a vault secret in your Postman Vault, first open your Postman Vault.
The environment you want to add a variable to must be active in the environment selector. If an environment isn't active, you can add a variable to an environment using one of the following options in the dropdown list:
Note that you can set global and environment variables as sensitive data, masking the values in the Postman app.
If the variable without a scope has the "vault:" prefix (for example, "vault:postman-api-key"), you can only add it to your Postman Vault as a vault secret.
To add a local value to a variable that you can shared with collaborators, learn how to edit variables directly in the global, environment, and collection scope.
Setting response body values as variables is only available in the Postman desktop app.
To define variables at any scope from a request's response body, do the following:
To view global variables, click Environments in the sidebar and select Globals.
To add a new global variable, do the following:
To download global variables, click
Export in the upper right of the workbench.
To edit an existing global variable, change the desired variable name, value, or description. To search for a global variable by name or value, click Search, and enter your search.
You can also learn about defining global variables in scripts and viewing and editing variables directly from a Postman element.
Changes to your variables are automatically saved.
To view environment variables, click Environments in the sidebar and select the environment you want to view.
To add a new environment variable, do the following:
To download environment variables, click
View more actions next to an environment and select Export.
To edit an existing environment variable, change the desired variable name, value, or description. To search for an environment variable by name or value, click Search, and enter your search.
You can add and edit variables if you have Editor access to an environment. If you have Viewer access, you're restricted to updating the local value of existing variables. Any variables you edit are available to you, but not to collaborators in your workspace. Learn about working with environments in your team and defining environment variables in scripts.
You can also learn about viewing and editing variables directly from a Postman element.
Changes to your variables are automatically saved.
To view collection variables, click Collections in the sidebar, select a collection you want to view, then select Variables.
To add a new collection variable, do the following:
To download collection variables, click
View more actions next to a collection and select More > Export. Learn more about exporting a collection.
To edit an existing collection variable, change the desired variable name, value, or description. To search for a collection variable by name or value, click Search, and enter your search.
With Editor access to a collection, you can add new collection variables, share values with your teammates, and update shared values. You can also define collection variables in scripts. If you have Viewer access to a collection, you can only update the local value of existing collection variables. Learn how to request Editor access to a collection.
You can also learn about viewing and editing variables directly from a Postman element.
Changes to your variables are automatically saved.
You can set variables and vault secrets programmatically in your request scripts.
Method | Use case | Example |
---|---|---|
pm.globals | Define a global variable. | pm.globals.set("variable_key", "variable_value"); |
pm.collectionVariables | Define a collection variable. | pm.collectionVariables.set("variable_key", "variable_value"); |
pm.environment | Define an environment variable in the current environment. | pm.environment.set("variable_key", "variable_value"); |
pm.variables | Define a local variable. | pm.variables.set("variable_key", "variable_value"); |
pm.vault | Define a vault secret in your Postman Vault. | await pm.vault.set("secret_key", "secret_value"); |
unset | Remove a variable. | pm.environment.unset("variable_key"); |
If you don't have Editor access to an environment, your script code will affect the local value but won't be synced or shared with your team.
Make sure you enable scripts to access your vault secrets. Otherwise, you'll receive an error in the Postman Console, and any code that comes after the method won't run. Also, you must use the
await
operator before eachpm.vault
method for it to run in your script.
For instructions on how to use variables in pre-request or post-response scripts, see Using variables in scripts.
With Editor access, you can set a global or environment variable as sensitive data. This masks the value, helping you avoid unintentionally sharing sensitive tokens, for example, to an unintended audience during screen sharing or live streaming. Postman stores variables as strings on the cloud. To learn about how Postman keeps your data safe, see Security at Postman.
Postman recommends that you use your Postman Vault to store sensitive data, such as API keys, as encrypted vault secrets. Only you can access and use values associated with your vault secrets, and they aren't synced to the Postman cloud.
To set a variable value as sensitive data, do the following:
Open a global or environment variable.
Click Mark as sensitive next to the variable name.
To set all variable values as sensitive data, select More > Mark all sensitive.
If you share a value that's set as sensitive data, Postman warns you about the outcome of sharing a sensitive value.
Your teammates can view the value of a variable set as sensitive data by clicking Show next to the variable's value.
To unset a variable value as sensitive data, do the following:
To unset all variable values as sensitive data, select More > Unmark all sensitive.
You can also learn how to set a value as sensitive data from the VS Code extension.
You can use double curly braces ("{{" and "}}") to reference variables throughout Postman. For example, to reference a "username" variable in your request's authorization settings, use the following syntax:
{{username}}
When you run a request, Postman resolves the variable and replaces it with your value. For example, you could have a request URL referencing a variable:
https://postman-echo.com/get?customer_id={{cust_id}}
Postman sends the value stored for the "cust_id" variable when the request runs. If "cust_id" has a "3" value, the request is sent to the following URL with the query parameter:
https://postman-echo.com/get?customer_id=3
If you want to access a variable from within a request body, wrap its reference in double-quotes:
{ "customer_id" : "{{cust_id}}" }
You can use variables in request URLs, parameters, headers, authorization, body, and header presets.
When you hover over a variable, Postman shows its value and its scope. As you add variables to your requests, Postman displays any existing variables.
The prompt indicates the local value, scope (highlighted by color), and Overridden status where relevant. If a global or environment variable is set as sensitive data, you can hover over the variable and click
Reveal to show its value. You can also press and hold ⌘ or Ctrl to show the values for all variables set as sensitive data.
If a variable doesn't have a value, Postman highlights it in red. Also, a red exclamation point displays on Variables in the upper-right of the workbench. For information on how to fix this, see Fixing empty variables.
Postman provides dynamic variables you can use in your requests. Examples of dynamic variables include:
See the Use dynamic variables to return randomly generated data section for a full list.
You can retrieve your local value of a variable in your scripts using the object representing the scope level and the .get
method:
//access a variable at any scope including local
pm.variables.get("variable_key");
//access a global variable
pm.globals.get("variable_key");
//access a collection variable
pm.collectionVariables.get("variable_key");
//access an environment variable
pm.environment.get("variable_key");
//access a vault secret
await pm.vault.get("secret_key")
Using
pm.variables.get()
to access variables in your scripts gives you the option to change variable scope without affecting your script functionality. This method returns the variable that has the highest precedence (or narrowest scope).Postman doesn't support using
pm.variables
to access and manipulate vault secrets.
To use dynamic variables in pre-request or post-response scripts, use pm.variables.replaceIn()
. For example:
pm.variables.replaceIn('{{$randomFirstName}}')
See Process data and script workflows using Postman JavaScript objects for more details about scripting with variables.
You can log variable values to the Postman Console while your requests run. Use the following syntax in your script to log the value of a variable:
console.log(pm.variables.get("variable_key"));
To view the results, click Console in the footer. You can also access the Console by selecting View > Show Postman Console.
The Collection Runner lets you import a CSV or a JSON file and use the values from the data file inside requests and scripts. You can't set a data variable inside Postman because it's pulled from the data file, but you can access data variables inside scripts, for example using pm.iterationData.get("variable_name")
.
For more details, see working with data files and the Postman JavaScript reference.
You can choose to share global, environment, and collection variables, syncing the values with the Postman cloud. By default, variables have a local value that only you can access in your instance of Postman. Share a variable value to create a separate, shared value your teammates can access. You can also update a shared value and stop sharing a value.
Shared values are also used with Postman features that run on the Postman cloud, like scheduled collection runs, monitors, the Postman CLI, and Newman.
Once the value is shared, you and your teammates can continue to work with your own local values during development and testing, without affecting the shared value. You can reset your local value back to the shared value, if you'd like.
For more information on working with variables as a team, see Work with environments as a team in Postman.
You can also learn how to share variable values from the VS Code extension.
You can create a shared value for a variable with Editor access to the element.
Be aware that the shared values of all variables are published with your documentation. Make sure your shared values don't contain sensitive information such as passwords or tokens.
To share a variable with your teammates, do the following:
Create a global, environment, or collection variable.
Click Share next to the variable's value you'd like to share.
To share all values, select More > Share all.
If you share a value that's set as sensitive data, Postman warns you that you're trying to share sensitive data. You can click Share Value to sync the value with the Postman cloud.
You can update a shared value for a variable with Editor access to the element. The shared value is updated based on your local value, sharing it with your teammates.
To update a shared value, do the following:
Open a global, environment, or collection variable.
Update your local value to differ from the shared value.
Click Edited next to a variable's value, then select Update shared value.
To update all shared values, select More > Update all shared values.
To copy a shared value to your clipboard, click
Edited next to a variable's value, then select
.
You can also update a shared value from a variable reference or the variables pane in a Postman element, such as a request or collection. Hover over the variable, update the local value, click Edited, then select Update shared value.
You can also stop sharing a shared value, removing it from the Postman cloud.
When you stop sharing a value, you may break API workflows that rely on it.
To stop sharing a variable with your teammates, do the following:
Open a global, environment, or collection variable.
Choose one of the following:
If your local value and the shared value are the same, click Shared next to the variable's value, then click Unshare to confirm.
If your local value and the shared value are different, click Edited next to the variable's value, then select Unshare.
To stop sharing all values, select More > Unshare all.
Once the variable has a shared value, you can continue to update the local value, without affecting the shared value. Local values enable you to develop and test using private credentials or experimental values, without risk of exposing sensitive data to others on your team. You can reset your local value when you're done, returning it to the shared value that's synced to the Postman cloud.
For example, your team could have a shared API key and individual API keys. You could do experimental development work locally using your personal key, but use the shared key for team collaboration.
To reset your variable's value, do the following:
Open a global, environment, or collection variable.
Update your local value to differ from the shared value.
Click Edited next to a variable's value, then select Reset value. Your local value is updated to match the shared value.
To reset all shared values, select More > Reset all shared values.
You can also reset a shared value from a variable reference or the variables pane in a Postman element, such as a request or collection. Hover over the variable, update the local value, click Edited, then select Reset.
Use the variables pane to view and edit the variables and vault secrets a Postman element uses and can access. With the variables pane, you can edit your variables and vault secrets in one location. You won't have to locate and update every variable in each scope and vault secret in your Postman Vault.
To access the variables pane, open a Postman element, then click Variables in the upper-right of the workbench. The variables pane opens on the right where you can view the following:
You can also hover over a reference to a variable or vault secret, then click Variables in request or All variables to open the variables pane.
Variable values set as sensitive data are stored in the active environment or globally in the workspace are masked by default.
To view variables and vault secrets used in a request, click Variables in the workbench to open the variables pane. The variables under Variables in request are defined at the environment, collection, or global variable scopes and show your local value. This also shows vault secrets stored in your Postman Vault.
You can edit your local value of a variable or vault secret that's referenced in a request. Open the variables pane, delete the existing value next to a variable or vault secret, then enter a new value.
You can also hover over the reference to the variable or vault secret, delete the existing value, then enter a new value.
If the request auth is set to Inherit auth from parent, you can view variables and vault secrets in the variables pane that are used in the Authorization tab of the request's parent collection or folder. Learn more about inheriting authorization from a parent element.
Under All variables in the variables pane, you can view and update variables and vault secrets that are available from your Postman elements. For requests that reference a variable or vault secret, select All variables to display all variables and vault secrets a request can access. Variables and vault secrets in this section can be referenced and resolved in the element that's open.
You can edit your local value of a variable or vault secret that's available from an element. Click Variables to open the variables pane, delete the existing value next to a variable or vault secret, then enter a new value.
You can also take the following actions to update the variables and vault secrets from the variables pane:
An empty variable is a variable that's referenced in a request but doesn't have a value. For example, Postman expects to find a value for "{{cust_id}}" in the https://postman-echo.com/get?customer_id={{cust_id}}
request. If Postman doesn't find a value for the variable, it's flagged as an empty variable and the request may fail when you send it.
A variable can be empty for the following reasons:
A vault secret can also be empty if it's missing a value and is referenced in a request. Learn how to fix empty vault secrets.
When you're working on an API request, Postman highlights empty variables in the URL builder and in the Params, Authorization, and Headers tabs. Postman highlights empty variable text in red. If your request has an empty variable, a red exclamation point displays on Variables in the upper right of the workbench.
To view empty variables referenced in a request, do the following:
To check if the variable exists and is available from the request, do the following:
Learn more about viewing and editing variables in an element.
From a request, you can set local variables programmatically in a pre-request script using
pm.variables.set
. When the variable is also referenced in the request, it'll display as Resolved via script in the variables pane. Environment, global, and collection variables set programmatically (for example,pm.environment.set
) are saved for later use at their respective scope. If you experience issues referencing a variable set programmatically, debug your requests with the Postman Console.
Last modified: 2025/09/10