0

In Postman calls, how can I update variable values in json body of a request with increasing time. I need to call the endpoint for 2048 times. Each call should have the end_time with 5mins difference. I'm unable to convert the value to normal time format.

I wrote this:

var moment = require("moment");
var t = pm.variables.get("t");
pm.environment.set('t', moment().add(1000, 'seconds').valueOf(t));
console.log("t", t);

I see an error:

{
    "ErrorCode": "1100",
    "Message": "request.end_time: Error converting value \"1581351445025\" to type 'System.TimeSpan'. Path 'end_time', line 10, position 29."
}

Sample request: (In Body)

{
  "monday": true,
  "tuesday": true,
  "wednesday": true,
  "thursday": true,
  "friday": true,
  "saturday": false,
  "sunday": false,
  "start_time": "7:30:00",
  "end_time": "{{t}}",
  "start_date": "2020-01-23",
  "end_date": "2020-05-23"
}
Learner
  • 157
  • 1
  • 4
  • 13

1 Answers1

0

In Pre-req script view

var moment = require("moment");
var t = pm.variables.get("t");
console.log("t: " + t);
var newT = moment().add(1000, 'seconds').valueOf(t); 
console.log("newT: " + newT);
postman.setEnvironmentVariable("newT", newT);

Then your request body should just change to use the new variable {{newT}}

Not sure why but using pm.environment.set wasn't setting the environment at all but postman.setEnvironmentVariable seems to work.

so cal cheesehead
  • 2,515
  • 4
  • 29
  • 50