How to Use Predefined Variables in Postman?
Postman also includes some predefined variables, such as {{$timestamp}} (current UNIX timestamp), {{$randomInt}} (a random integer), and so on. These variables can be directly used in requests without prior definition.
In Postman, variables can assist you in managing and storing frequently changing data, such as server environments, session tokens, and so forth. There are several different types of variables in Postman, including global variables, environment variables, collection variables, and local variables. Postman also includes some predefined variables, such as {{$timestamp}}
(current UNIX timestamp), {{$randomInt}}
(a random integer), and so on. These variables can be directly used in requests without prior definition.
Below are steps on how to use Postman's predefined variables:
1.Create or open a request
Open a project in Postman, then create or open an HTTP request, select your HTTP method, and input your request URL.
2.Utilize predefined variables
You can use predefined variables anywhere you need dynamic values. For example, if you need a URL parameter to contain a random integer, you can use syntax like ?random={{$randomInt}}
in the URL.
3.Send the request
Predefined variables will be replaced with their respective values before the request is sent. After sending the request, view the actual sent request in Postman's "Console," which includes resolved variable values.
Using predefined variables for testing
In the "Tests" tab, you can also utilize predefined variables to write assertions and conduct dynamic testing. For example, you can test if the response time is less than a specific value.
var responseTime = pm.response.responseTime;
pm.test("Response time is less than 200ms", function () {
pm.expect(responseTime).to.be.below(200);
});
Postman Predefined Variables Appendix
Remember, while predefined variables are incredibly useful, it's important to understand the meaning and purpose of each before using them. This way, you can leverage Postman's functionality more effectively in API testing and development processes.
You can access the official Postman documentation to view the list of predefined variables.
Reference:
https://learning.postman.com/docs/writing-scripts/script-references/variables-list/
Learn more: