What is an Environment in Postman?

An Environment in Postman is a collection of key-value pairs used to store variables such as:

  • API base URLs
  • Authentication tokens
  • User IDs
  • Request parameters

Environments allow testers to switch easily between different setups such as Development (Dev), Quality Assurance (QA), and Production (Prod) without modifying individual API requests.


Why Are Environments Useful?

Environments provide several benefits:

Advertisement
  • Store reusable variables.
  • Manage dynamic data efficiently.
  • Switch between Dev, QA, and Production with a single click.
  • Reduce manual changes and configuration errors.
  • Simplify authentication token management.

Interview Tip:
"Instead of manually changing API URLs, we stored the base URL in an environment variable like {{base_url}}. Switching environments automatically updated every request, and pre-request scripts handled token generation."


Environment Variables

Environment Variables are key-value pairs associated with a specific Postman environment.

They store values that differ between environments, such as:

  • Base URLs
  • Authentication tokens
  • API credentials
  • Request parameters

Why Use Environment Variables?

  • Avoid hardcoding values.
  • Easily switch between Dev, QA, and Production.
  • Simplify dynamic configuration.
  • Improve request reusability.

How to Create an Environment Variable

  1. Open Environments.
  2. Click New Environment.
  3. Enter an environment name.

Example:

 
QA Environment
 
  1. Add a variable.

Example:

Variable Value
base_url https://qa.api.example.com
  1. Save the environment.

Using an Environment Variable

Reference it in any request using:

 
{{base_url}}
 

Global Variables

Global Variables are accessible across the entire Postman workspace.

They can be used in:

  • All collections
  • All requests
  • All environments

Key Features

  • Available everywhere.
  • Shared across all environments.
  • Can be updated dynamically using scripts.
  • Useful for values that rarely change.

Common Uses

  • API keys
  • Organization IDs
  • Shared configuration values

Collection Variables

Collection Variables belong to a specific Postman collection.

They are shared only by requests inside that collection.

Key Features

  • Limited to one collection.
  • Easier to maintain than repeating values in every request.
  • Ideal for collection-specific configuration.

How to Create a Collection Variable

  1. Select the collection.
  2. Open the Variables tab.
  3. Click Add Variable.

Example:

 
collection_base_url
 

Interview Tip:
"We stored common values shared by all requests in Collection Variables, while environment-specific values such as base URLs and authentication tokens were stored in Environment Variables."


Variable Scope at a Glance

Variable Type Scope Best Used For
Global Variables Entire workspace Values shared across all collections and environments
Environment Variables Selected environment Environment-specific URLs, tokens, credentials
Collection Variables Single collection Shared values within one collection
Dynamic Variables Generated during execution Random test data

Dynamic Variables

Dynamic Variables are predefined Postman variables that automatically generate random values during request execution.

They are extremely useful for creating unique test data.

Common Dynamic Variables

Variable Purpose
{{$randomEmail}} Generates a random email address
{{$guid}} Generates a unique UUID
{{$timestamp}} Generates the current Unix timestamp

Example

 
{{$randomEmail}}
 

Each request generates a unique email address automatically.

When to Use Dynamic Variables

  • User registration
  • Transaction IDs
  • Unique usernames
  • Random emails
  • Timestamps
  • Test data generation

Interview Tip:
"We used {{$randomEmail}} during user registration testing to avoid duplicate email validation errors."

Note:
Dynamic variables should be used only when unique values are required. Avoid them when fixed or predictable values are needed.


Creating a Postman Collection

A Postman Collection is an organized group of related API requests.

Collections make it easier to:

  • Organize APIs.
  • Reuse requests.
  • Execute multiple requests together.
  • Share APIs with team members.

Steps to Create a Collection

  1. Click New.
  2. Select Collection.
  3. Enter a collection name.
  4. Click Create.
  5. Add requests using Add Request.
  6. Organize requests into folders if required.
  7. Save the collection.

Interview Tip:
"We grouped related APIs such as Create User, Get User, Update User, and Delete User into a single collection and executed them together using the Collection Runner."


Running a Postman Collection

There are three common ways to execute a Postman collection.

Collection Runner

The Collection Runner executes all requests sequentially within Postman.

It is commonly used for:


Newman

Newman is Postman's command-line collection runner.

It is primarily used for:

  • CI/CD automation
  • Jenkins integration
  • GitHub Actions
  • Azure DevOps
  • Command-line execution

Postman Monitors

Postman Monitors execute collections automatically at scheduled intervals.

They help monitor:

  • API availability
  • API health
  • Performance
  • Response times

Interview Tip:
"We integrated Newman with Jenkins to execute API collections automatically after every deployment and used Postman Monitors to continuously verify production API health."


FAQs

What is an Environment in Postman?

An Environment is a collection of key-value pairs used to store values such as API URLs, authentication tokens, and request parameters, allowing easy switching between Development, QA, and Production environments.


What is the difference between Global, Environment, and Collection Variables?

  • Global Variables are available throughout the entire Postman workspace.
  • Environment Variables are available only within the selected environment.
  • Collection Variables are available only inside a specific collection.

What are Dynamic Variables?

Dynamic Variables are predefined Postman variables that automatically generate unique values such as random emails, UUIDs, and timestamps during request execution.

Examples include:

  • {{$randomEmail}}
  • {{$guid}}
  • {{$timestamp}}

How do you create a Postman Collection?

Click New → Collection, provide a collection name, add requests, organize them into folders if needed, save the collection, and execute it using the Collection Runner.


How do you run a Postman Collection?

A Postman Collection can be executed using:

  • Collection Runner for manual execution.
  • Newman for command-line execution and CI/CD automation.
  • Postman Monitors for scheduled execution.

What is Newman?

Newman is Postman's command-line collection runner used to execute Postman collections outside the Postman application. It is commonly integrated with CI/CD tools such as Jenkins, GitHub Actions, and Azure DevOps to automate API testing.