Examples of Postman Dynamic Variables

I am sure you all know what a variable is, as shown in the below good old C++ example; it is a symbolic name associated with a value that can be changed.

variable.cpp

C++




#include <iostream>
using namespace std;
 
int main()
{
    int num;
    num = 4;
    cout << "Before changing the Number is:" << num << endl;
    num = 14;
    cout << "After changing the Number is:" << num << endl;
    return 0;
}


Output:

Before changing the Number is:4

After changing the Number is:14

Here the value of num can be changed as and when needed; dynamically. Then what does Dynamic variable mean?

Let’s say you are working on an Employee Management Application, you want to create an account for all the employees who have joined your organisation with a default dummy password. But you don’t have to handle the hassle of generating a stronger passwords; instead you can use $randomPassword when you are saving that user details.

Example 1:

Copy and paste this code in the body of a POST request in Postman new window, and then click on the code snippet icon on the right. This shows the request data that will be sent to the API.

Javascript




{
    "name": "Akanksha",
    "department": "Engineering",
    "password": "{{$randomPassword}}",
    "shouldResetPassword": true,
    "employeeId": "EMP-896"
}


1. Postman’s Dynamic Variable {{$randomPassword}} usage

Example 2:

Javascript




{
    "name": "Bindu Kumari",
    "department": "Operaions",
    "password": "{{$randomPassword}}",
    "shouldResetPassword": true,
    "employeeId": "EMP-990"
}


Paste this code in Postman’s new window and click on the code snippet icon to see the data that will be sent to the API in the request.

Postman’s Dynamic Variable {{$randomPassword}} usage

If you take a close look at this example we have used the $randomPassword enclosed in {{ }}.

{{$dynamic_variable_name}}

This is the right syntax to use a Dynamic variable in PostmanPostman. Here we got two different values for the field password for two requests. Hence the name Dynamic. It can pass different values to the field each time a request is made.

Note:

Random default password is demonstrated here just for reference and not to encourage to use this for real world applications. Depending on the use case and app flow a strong authentication flow is usually setup; this includes not storing the passwords in the app or database in plain text.

Postman Dynamic Variables

Postman’s dynamic variables are powerful tools to help developers perform API testing with less effort. They provide flexible ways to inject and manage data directly into requests and scripts. They can be configured in the folder, environment, or even in a single request. They promote consistency and also by simplifying repetitive tasks they save a lot of time.

Table of Content

  • Types of Dynamic Variables
  • Step By Step Working with Dynamic Variables
  • Examples of Postman Dynamic Variables
  • Advanced Techniques and Tips
  • Troubleshooting Dynamic Variables
  • Conclusion

Similar Reads

Prerequisites

This article requires the user to have some basic experience with Postman in making API requests. If not, just download Postman and give it a try; it is easy to interpret. Once you are comfortable with the options available in the tool and can hit a couple of APIs, kindly follow along....

Types of Dynamic Variables

Predefined Variables...

Step By Step Working with Dynamic Variables

Step 1: Setup Node App...

Examples of Postman Dynamic Variables

...

Advanced Techniques and Tips

...

Troubleshooting Dynamic Variables

...

Conclusion

...