Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I save value of dynamic variable in Postman?

Tags:

postman

Postman allows to generate random dummy data by using pre-defined variables, on example this one would be replaced by random company name:

{{$randomCompanyName}}

Using pre-defined variables multiple times return different values per request.

The question is how to save once generated value to the variable for further usage on example in tests, something like(it doesn't work):

pm.variables.set("company", {{$randomCompanyName}});

Thanks.

like image 303
Tarás Avatar asked Oct 20 '25 09:10

Tarás


1 Answers

You can use the .replaceIn() function with that {{...}} syntax in the sandbox.

pm.globals.set("company", pm.variables.replaceIn('{{$randomCompanyName}}'));

I've used a global variable to store the value as you would want to use it again. You could also use either the environment or collectionVariables scope to do the same thing.

like image 121
Danny Dainton Avatar answered Oct 22 '25 04:10

Danny Dainton