Site icon #Ludens

How to use dynamic(random) variables on Postman

When I test some APIs, I sometimes need fake name, phone number, emails, and so on.

On Postman, you can use random name, phone numbers, uuids easily. Just type predefined {{$variable_name}} where you want use them, then Postman automatically set random data.

Dynamic variables that I use frequently

I use below variables especially for API testing.

VariablesDescriptionExample
{{$guid}}UUID version 4611c2e81-2ccb-42d8-9ddc-2d0bfa65c1b4
{{$timestamp}}UNIX timetamp1562757107
{{$isoTimestamp}}ISO format timestamp2020-06-09T21:10:36.177Z
{{$randomIP}}IPv4 address216.7.27.38
{{$randomUserAgent}}User AgentMozilla/5.0 (Macintosh…
{{$randomFirstName}}First NameEthan
{{$randomLastName}}Last NameWillms
{{$randomFullName}}Full NameConnie Runolfsdottir
{{$randomPhoneNumber}}10-digit phone number700-008-5275
{{$randomPhoneNumberExt}}12-digit phone number27-199-983-3864
{{$randomExampleEmail}}Email addressTalon28@example.com

Use dynamic variables in Pre-request / Tests scripts

If you want use dynamic variables in Pre-request script or Tests scripts, you should use pm.variables.replaceIn().

// Example for using the random eamil variable on script
var email = pm.variables.replaceIn('{{$randomExampleEmail}}');
console.log(email);

References

Exit mobile version