Postman mock servers - Mock a response with a random 10-digit number

Viewed 479

I’m using Postman 8.12.1. I’m creating a mock server and trying to set up my mock response for a certain request so that the response returns a random 10 digit number. However, the only pre-built function I can find is “randomInt”

enter image description here

That seems to have a very limited range. Is there a way I can configure my response to return a random integer that has 10 digits? It is fine if the leading digits are zeroes.

2 Answers

https://documenter.getpostman.com/view/8296678/UUy65Pz5

Postman doesn't allow to update mock server dynamically , but due to its sweet API first design , we can use Postman API to update the environment variables and this will reflect in the mock server response

Please see the attached public collection to know how to do this .

enter image description here

Here i am getting the environment and the correseponding variable , and then updating it before calling the mock server

So when we call the mock server , it always gets the updated value.

you can store the update variable request in a variable as

pm.variable.set("request",pm.request)

and then use it in pre-prequest as

pm.sendRequest(pm.variables.get("request"))

You can use $timestamp which will return 10 digits number:

The current UNIX timestamp in seconds (as 1562757107)

You have similar options as $randomBankAccount

A random 8-digit bank account number

Or $randomPhoneNumber

A random 10-digit phone number (as 700-008-5275)

Related