Postman Environment Variables- API Testing using Postman

In this tutorial you will learn postman environment variables , how to create environment and set variables in postman.

What is an Environment in Postman?

An environment is a set of key-value pairs. The key represents the name of the variable. You can use a data editor to modify an environment.

While working with APIs, you often need different setups for your local machine, the development server, or the production API. Environments let you customize requests using variables so you can easily switch between different setups without changing your requests.

You don't need to remember all those values once they are in Postman. You can download environments, save them as JSON files, and upload them later.

You can create, share, duplicate, export, and delete an environment. You can also import an environment as a single JSON file.

Creating a new environment

You can create a new environment from the:

  • Manage Environments icon
  • New button
  • Launch screen

What is Variable?

Variables are symbolic names that represent the information you store in them. The information the variables represent can change, but the operations on the variable remain the same. Variables in Postman work the same way.

You can assign five types of variable scopes:

  • Global
  • Collection
  • Environment
  • Data
  • Local

Data variables

The Collection Runner lets you import a CSV or a JSON file, and then use the values from the data file inside HTTP requests and scripts. We call these 'data variables'.

To use them inside Postman, follow the same syntax as environment or global variables.

Data variables in requests 

Variables inside the Postman UI are enclosed inside curly braces

For example, in the screenshot below, {{username}} and {{password}} inside URL parameters would be replaced by corresponding values from the data file:

Dynamic variables

Postman has a few dynamic variables that you can use in your requests.

Dynamic variables cannot be used in the Sandbox. You can only use them in the {{..}} format in the request URL / headers / body.

{{$guid}} : Adds a v4 style guid

{{$timestamp}}: Adds the current timestamp

{{$randomInt}}: Adds a random integer between 0 and 1000

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.