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" } }
' 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.
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.
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.
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).
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" } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With