Iāve got the following pre-request script:
var moment = require('moment');
pm.environment.set('time0', moment().add(0, 'minutes').toISOString());
pm.environment.set('time1', moment().add(1, 'minutes').toISOString());
pm.environment.set('time2', moment().add(2, 'minutes').toISOString());
pm.environment.set('time3', moment().add(3, 'minutes').toISOString());
pm.environment.set('time4', moment().add(4, 'minutes').toISOString());
pm.environment.set('time5', moment().add(5, 'minutes').toISOString());
pm.environment.set('time6', moment().add(6, 'minutes').toISOString());
pm.environment.set('time7', moment().add(7, 'minutes').toISOString());
pm.environment.set('time8', moment().add(8, 'minutes').toISOString());
pm.environment.set('time9', moment().add(9, 'minutes').toISOString());
pm.environment.set('time10', moment().add(10, 'minutes').toISOString());
And the Body references those timeX variables:
{
"id": "ID1",
"timestamp": "{{time0}}",
"value": 10
},
{
"id": "ID1",
"timestamp": "{{time1}}",
"value": 12
},
{
"id": "ID1",
"timestamp": "{{time2}}",
"value": 10
},
{
"id": "ID1",
"timestamp": "{{time3}}",
"value": 8
},
Iām unsure how to turn this into a for loop that fills in the corresponding time variables in a single POST. It works as-is, but Iām pretty sure thereās a way to reduce the 70 time variables (from now-10 minutes to now+60 minutes) in the pre-request script to a loop. Anyone know how this can be done? Thanks.