Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make dynamic name text field in Postman

Tags:

json

postman

I'm using Postman to make REST API calls to a server. I want to make the name field dynamic so I can run the request with a unique name every time.

{   "location":   {     "name": "Testuser2", // this should be unique, eg. Testuser3, Testuser4, etc     "branding_domain_id": "52f9f8e2-72b7-0029-2dfa-84729e59dfee",     "parent_id": "52f9f8e2-731f-b2e1-2dfa-e901218d03d9"   }  } 
like image 584
manoj Avatar asked Sep 22 '14 12:09

manoj


People also ask

How do you set dynamic values in Postman?

' In the request URL section, a dynamic variable should be written in {{__}} format. Let's say you have to pass an integer number from 1 to 1000, so for that, you need to add {{$randomInt}}. Like the above example of the number variable, Postman supports so many other dynamic variables as well.

How do you generate a random name in a Postman?

Postman uses the faker library to generate sample data, including random names, addresses, email addresses, and much more. You can use these pre-defined variables multiple times to return different values per request. You can use these variables like any other variable in Postman.

How can we create dynamic environment variable in Postman?

Variables quick start Save, then close the environment tab. Open a new request tab and enter https://postman-echo.com/get?var={{my_variable}} as the URL. Hover over the variable name to inspect the variable's value and scope. Select Send and send the request.


2 Answers

In Postman you want to use Dynamic Variables.

The JSON you post would look like this:

{   "location":   {     "name": "{{$guid}}",      "branding_domain_id": "52f9f8e2-72b7-0029-2dfa-84729e59dfee",     "parent_id": "52f9f8e2-731f-b2e1-2dfa-e901218d03d9"   }  } 

Note that this will give you a GUID (you also have the option to use ints or timestamps) and I'm not currently aware of a way to inject strings (say, from a test file or a data generation utility).

like image 117
MisterJames Avatar answered Sep 20 '22 08:09

MisterJames


In Postman you can pass random integer which ranges from 0 to 1000, in your data you can use it as

{   "location":   {     "name": "Testuser{{$randomInt}}",     "branding_domain_id": "52f9f8e2-72b7-0029-2dfa-84729e59dfee",     "parent_id": "52f9f8e2-731f-b2e1-2dfa-e901218d03d9"   }  } 
like image 40
Pratik Charwad Avatar answered Sep 21 '22 08:09

Pratik Charwad