# Managing Variables in Postman: Scopes, Vault, and Sharing

Source: https://www.youtube.com/watch?v=7C2zk9ziWBY
Recap page: https://rapidrecap.app/video/7C2zk9ziWBY
Generated: 2025-12-23T14:33:19.896+00:00

---
## Quick Overview

Postman variables utilize four main scopes—Global, Environment, Collection, and Local—which dictate their accessibility and persistence, allowing users to manage data like URLs and tokens effectively across different testing contexts, with Collection variables being shared within a collection and Local variables being limited to the current request execution.

**Key Points:**
- Postman variables feature four primary scopes: Global (entire workspace), Environment (selected environment), Collection (within one collection), and Local (current request only).
- Global variables persist across the entire workspace and are typically used for shared constants or temporary debugging values.
- Environment variables allow defining different sets of variables (e.g., staging, test) for specific environments, often used for stage-specific URLs or tokens.
- Collection variables are scoped within a single collection, ideal for API versions or static values specific to that collection.
- Local variables are temporary, persisting only for the current request execution, suitable for transient calculations or testing logic.
- Variables can be set dynamically using scripts (e.g., `pm.collectionVariables.set("accountId", response.account.id)`), capturing values like a newly created account ID.
- Sensitive values, like API keys, can be marked as secrets within environments, masking the value and storing it securely, optionally using the Vault for even more secure storage.

![Screenshot at 00:11: The presenter introduces Chapter 1 on Variable Scopes, displaying a summary table that contrasts the four variable types \(Global, Environment, Collection, Local\) based on their scope, persistence, and typical use cases.](https://ss.rapidrecap.app/screens/7C2zk9ziWBY/00-00-11.jpg)

**Context:** This video tutorial, presented by Gbadebo Bello, a Developer Advocate at Postman, explains the crucial concept of variable scoping within the Postman platform. It details the four distinct variable scopes—Global, Environment, Collection, and Local—and demonstrates how to set, use, and share variables to manage different configuration values (like base URLs or authentication tokens) for API testing across various contexts.

## Detailed Analysis

The video thoroughly explains Postman variable scoping, detailing four levels: Global, Environment, Collection, and Local. Global variables are accessible across the entire workspace and persist, suitable for shared constants. Environment variables allow setting different values for distinct environments like staging or test, used for environment-specific URLs or tokens. Collection variables are restricted to within one collection, useful for collection-specific static values. Local variables are the most transient, existing only for the duration of the current request, perfect for temporary calculations. The presenter demonstrates how to set a variable programmatically in a post-response script using `pm.collectionVariables.set("variable_key", response.account.id)` to capture data from an API response, like a newly created account ID. Furthermore, the video covers sharing variables, showing that collection variables, when marked as shared (cloud icon), sync across the Postman cloud, accessible by teammates. It also touches upon securing secrets within environments by marking variables as sensitive (eye-crossed-out icon) and leveraging the Vault for storing sensitive credentials like API keys, which remain local unless explicitly shared.

### Variable Scopes Overview

- Global scope affects the entire workspace
- Environment scope affects a selected environment
- Collection scope is limited to one collection
- Local scope is current request only.

### Variable Persistence and Use

- Global and Environment variables persist (Yes)
- Collection variables persist (Yes)
- Local variables do not persist (No)
- Typical uses include shared constants (Global), stage-specific URLs (Environment), API versions (Collection), and temporary logic (Local).

### Setting Variables Programmatically

- Use snippets to find `pm.collectionVariables.set("variable_key", variable_value)` in scripts to dynamically set variables based on response data, such as capturing an account ID.

### Variable Sharing

- Collection variables can be shared by clicking the share icon, synchronizing the value across the Postman cloud for teammates to use.

### Securing Sensitive Data

- Environment variables can be marked as sensitive (secret), masking the value; sensitive values in the Vault are stored locally and encrypted, requiring explicit sharing.

![Screenshot at 00:11: The presenter introduces Chapter 1 on Variable Scopes, displaying a summary table that contrasts the four variable types \(Global, Environment, Collection, Local\) based on their scope, persistence, and typical use cases.](https://ss.rapidrecap.app/screens/7C2zk9ziWBY/00-00-11.jpg)
![Screenshot at 00:34: The presenter navigates to the Environments tab and clicks on 'Globals' to show the workspace-wide variable settings, which include a 'BankServ Mock API' and specific staging/test environments.](https://ss.rapidrecap.app/screens/7C2zk9ziWBY/00-00-34.jpg)
![Screenshot at 01:54: Demonstration of highlighting the base URL in the request URL bar and right-clicking to select 'Set as new variable', initiating the process to define a new variable named 'baseUrl'.](https://ss.rapidrecap.app/screens/7C2zk9ziWBY/00-01-54.jpg)
![Screenshot at 03:14: The presenter highlights an API token value in the Headers tab and right-clicks to select 'Set as new variable', choosing the 'Vault' scope for secure storage of the token.](https://ss.rapidrecap.app/screens/7C2zk9ziWBY/00-03-14.jpg)
![Screenshot at 05:15: Code snippet in the post-response script showing how to dynamically set a collection variable using the response data: pm.collectionVariables.set\("accountId", response.account.id\);.](https://ss.rapidrecap.app/screens/7C2zk9ziWBY/00-05-15.jpg)
