How to use Environments in Postman?

What are environments?

While working with APIs, you will often need to have different setups. For example, your local machine, the development server, or the production API. Environments give you the ability to customize requests using variables. This way you can easily switch between different setups without changing your requests. You won’t have to worry about remembering all those values once they are in Postman. Environments can be downloaded and saved as JSON files and uploaded later.

Steps to create a new environment

Click the gear icon in the upper right corner of the Postman app and select Manage Environments.

Screenshot of getpostman

Click the Add button to create a new environment.

screenshot of bpconcjcammlapcogcnnelfmaeghhagj

Provide Environment name Like Local/Development or Production.

Each environment is a set of key-value pairs, with the key as the variable name.

e.g Here we create two keys which can be used while triggering API’s

API_URL

APP_VERSION

screenshot of bpconcjcammlapcogcnnelfmaeghhagj

We can also set global variables which can be accessible in all the environments

Set Key Values as set earlier while creating an environment and then click on save button.

screenshot of bpconcjcammlapcogcnnelfmaeghhagj

Steps to use environment

Select an active environment

Click the drop-down in the upper right corner of the Postman app to select an active environment, or type in the environment name. Once you select an environment, you can access variables within the active environmental scope.

screenshot of active enviironment

Access Environment Variables

After selecting the environment you can easily access the variable in Body, Headers or in Request URL.

Note: The variable name will be enclosed in double curly braces. e.g {{API_URL}}. You can also get the suggestion of variable by typing single curly braces ‘{‘

In the below screenshot we have used variables in Request Url and in Body parameters.

screenshot of body parameters

Note: Environment and global variables will always be stored as strings. If you�re storing objects/arrays, be sure to JSON.stringify() them before storing, and JSON.parse() them while retrieving.

Joe Parker

We boast of the best in the industry plugins for eCommerce systems and has years of experience working with eCommerce websites. We provide best plugins for platforms like - Magento, Prestashop, OpenCart and Shopify . We also provide custom module development and customization services for the website and modules..

Leave a Reply

Your email address will not be published. Required fields are marked *