How we can use faker in Postman v 7.2

Now postman support faker library in v 7.2

How we can use it any code example ?

I want to create some fake data in pre request script.

Hey @mehran.shafqat

You will find more information about it here, these are dynamic variables and would work in the same places that {{$randomInt}} can be used.

1 Like

well why this is not working in pre-req script

var x = “{{$randomInt}}”
console.log (x)

its not printing any random value

Taken from the dynamic variables section:

Note that 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

That’s expected behavior because in pre-request script the variables are not resolved.

There’s a workaround:

const {Property} = require('postman-collection');

let randomInt = Property.replaceSubstitutions("{{$randomInt}}");


We are planning to add an API for variable substitution in scripts.
Please follow the original GitHub feature request for more updates.

1 Like