postman
  1. postman-variables

Variables in Postman

Syntax

To create a variable in Postman, use the following syntax:

{{variable_name}}

Example

Here's an example of declaring and using a variable in Postman:

// Declare a variable
let name = 'John';

// Use the variable in a request
pm.sendRequest('https://example.com/users?name={{name}}', function (err, res) {
    console.log(res.json());
});

Output

The output will vary depending on how the variable is used within the request.

Explanation

Variables in Postman allow you to store and reuse values across different requests and environments. They are enclosed in double curly braces ({{ }}) and can be set and updated in different ways, such as through environment variables or scripts. Variables are commonly used for dynamic data, such as user input or data retrieved from a previous request.

Use

Variables are useful in a number of scenarios, including:

  • Storing and reusing commonly used values (e.g. base URLs, API keys)
  • Dynamically passing values between requests (e.g. user input, response data)
  • Customizing requests based on different environments (e.g. development, production)

Important Points

  • To create a variable, enclose it within double curly braces ({{ }}).
  • Variables can be set and updated using environment variables or scripts.
  • Variables can be used to pass dynamic data between requests and customize requests based on the environment.

Summary

Variables in Postman provide a powerful way to store and reuse values across different requests and environments. They are an essential tool for working with dynamic data and customizing requests for different scenarios.

Published on: