How to store a list of value and then send one of those values randomly in an API call?

Hi @jarrodedg :wave:

If you are going to pick the defined array, it should declared as below.

var Cities = ["San Francisco", "San Diego", "Boston"];

pm.environment.set('Cities',Cities);

pm.environment.set("CITY", Cities[Math.floor(Math.random() * Cities.length)]);

After assigning the array to a variable, the last line is for pick the random cities from the defined array.

Now body of the request should contain,

    "Location": {
        "randomCity": "{{CITY}}",

From the defined array, among the three values it will pick one for every single hit. Is this is your expectation? :blush:

2 Likes