Managing Variables in Postman: Scopes, Vault, and Sharing
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., ), 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.
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 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.