Adventures with Postman: Dynamic Variables

Postman

Dynamic variables allow you to randomly generate values for your Postman requests, e.g. First Name and Company Name.

Postman dynamic variables include:

So what is the easiest less difficult way to do this?

Let’s Open Postman.

Create a new request.

For this example, I have a POST request that creates a new user.

I want to generate random values for id, name and email.

As far as an email goes, I will use my Gmail account so I can use the plus sign hack, e.g. GMAIL_USER_NAME+name@gmail.com.

Select the Pre-request Script tab and add the following code:

I create a random name using the Postman dynamic variables for {{$randomFirstName}} and {{$randomLastName}}.

I then remove the space between the name so I can build the email address to make use of my Gmail account.

Select the Body and add the following code:

The {{$guid}} syntax uses Postman’s common dynamic variables.

I add the dynamic variables for name and email using the curly brace syntax.

Run the request, and I receive the following response:

That’s it!

Simple way to create fake data that is a bit meaningful than random numbers and unique identifiers.

Leave a Reply

Your email address will not be published. Required fields are marked *