User Guide: How to Use Environment Variables in Postman

In this article, I will provide a detailed introduction to Postman environment variables and completely explain how to use them.

When using Postman's environments, it is essential to make use of environment variables. So, what are Postman environment variables? How can they be utilized? In this article, I will provide a detailed introduction to Postman environment variables and completely explain how to use them.

What are Postman Environment Variables?

Postman environment variables are variables associated with a specific environment in Postman. These variables represent configuration values or data used during the development and testing of APIs. By using Postman environment variables, you can set dynamic values in various places, such as request URLs, headers, and body data. This facilitates the easy switching and reuse of API endpoints, parameters, authentication information, and more.

Types of Environment Variables

When setting environment variables in Postman, there are two types available:

  • Default Type: A plain text variable without any additional properties.
  • Secret Type: Similar to a password, this type hides both the initial and current values across all workspaces. It is used to prevent the unintended disclosure of sensitive data.
image.png

Examples of Using Environment Variables

During API development, there are various scenarios where it is necessary to utilize environment variables. For example:

  • Test Data: By defining data used in test scenarios (e.g., information for test users) as common variables, the same data can be reused across different test cases. If there are changes to the test data, updating the variable's value will reflect those changes automatically.
  • Environment-Specific Settings: By defining different configurations for each environment (e.g., development, staging, production) as common variables, you can easily change settings when switching environments.

How to Using Environment Variables in Postman

Adding New Environment Variables

When you create an environment in Postman, you can add environment variables to that environment.

Step 1:

Select "Environments" from the left menu and switch to the relevant environment.

Step 2:

In the "VARIABLE" form, input the variable name, type, initial value, and other details to add the environment variable.

image.png

Step 3:

Click "Save" to save the changes.

Using Environment Variables

Environment variables can be utilized within the Postman user interface. Here are some common ways to use environment variables:

  1. Dynamic Setting of Request URLs: You can use environment variables to switch the base URL of the API between different environments or set path parameters and query parameters.
  2. Setting Headers and Authentication Information: Environment variables make it easy to set values for request headers and authentication tokens. This allows you to use different values for various environments or users.
  3. Dynamic Setting of Body Data: Environment variables can be used to dynamically set data within the request body. For example, you can customize requests using variables for usernames, passwords, etc.

Environment variables are used in Postman by enclosing the variable name in double braces ({{variableName}}) within fields in your collections or requests. This allows Postman to replace the variable with its value.

image.png

Using environment variables enhances the flexibility and efficiency of testing and development with Postman. They can be utilized in various scenarios, such as switching settings between different environments and improving reusability.

Setting Up and Using Environment Variables with EchoAPI

EchoAPI is a powerful and user-friendly API management tool that surpasses Postman. With EchoAPI, you can easily set up environments and variables. Additionally, it offers excellent collaboration features, significantly enhancing team development efficiency.

Setting Environment Variables is Easy

As shown in the next image, you can set environment variables for your environment in EchoAPI through very intuitive operations. You can fix the values of environment variables or set them to dynamic values.

1.Setting Environment Variables

image.png

2.user Environment Variables

image.png

Switch Environments with One Click

Switching environments is also very straightforward. Simply click the dropdown list in the upper right corner, and you can switch to the required environment with just one click.

image.png

EchoAPI: Perfectly Compatible with Postman Environment Variables

EchoAPI is fully compatible with Postman format data. Therefore, you can export collections from Postman and import them into EchoAPI, allowing you to use Postman environment variables and other data within EchoAPI.

Step 1: Use Postman's "Export Collection" Feature

Utilize Postman's "Export Collection" feature to completely export your collection data.

image.png

Step 2: EchoAPI Supports Various Formats

EchoAPI supports various formats. To import a Postman collection, select "Postman," allowing you to perfectly import Postman data into EchoAPI.

image.png

Step 3: EchoAPI Can Perfectly Parse Postman Data

Since EchoAPI can perfectly parse Postman data, you can directly use specifications, environments, variables, schemas, and more in EchoAPI.

image.png