Using moment in Prerequest:
var yesterday = moment().subtract(1, 'days').format("yyyy-MM-DD");
console.log(yesterday);
var pastDate = yesterday;
pm.environment.set("pastDate", yesterday)
Request Body:
"AccountId": 1,
"StartDate": {{pastDate}}
Response:
{
"errors": {
"StartDate": [
"Unexpected character encountered while parsing value: 2. Path 'StartDate', line 7, position 18.",
"Input string '022-06-26' is not a valid number. Path 'StartDate', line 7, position 27."
]
},
"type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
}
However when looking at the value in the Enviroment: pastDate: 2022-06-26
So it seems the first character of the variable is being stripped? Not sure how to address this.