Give variable data for a PUT to give random references that I have defined in a table beforehand

Hello all,

I would like to vary a data item for a PUT to give random references that I defined in a table beforehand.

My body:
“ecoparticipations”: [
“productReference”: {{ReferenceEcopart}},
“type”: “ECO_DDS_ITEM”,
“startDate”: “2020-12-20”,
“amount”: 6

I would like to variable each value with random data that I would have defined in a table.


ProductReference table: [777765413, 777791817, 777702826, 71625278, 787262552]
amount array: [16, 78, 3, 99, 66]

Is it possible to randomly recover it is given to put them in my body?

Thank you for your help !

PS: sorry for my english i’m french people :wink:

Hi @alexisjah!

If you need to access data from this array in multiple requests, I would recommend storing it in the environment, and retrieving it as needed. Otherwise, you can just store it in the script. Please see example below:


Pre-request script on request:

// if you need to store your array in the environment, this could be replaced with a declaration of the literal array
var arrayData = JSON.parse(pm.environment.get('array'));

var index = Math.round(Math.random()*(arrayData.length-1));

var randomValue = arrayData[index];

1 Like