var now = new Date();
var timestamp = now.toISOString(); //or whatever format you want.
// console.log(timestamp) <-- It appears as as so 2025-03-10T03:01:14.954Z
pm.environment.set("timestamp", timestamp);
body
{
"TicketTitle": "Main Title",
"DateCreated": {{timestamp}},
"CreatedBy": "John Doe",
// Other Fields
}
所有人看起来都很好,很花花公子,但是我遇到了一个错误。我不明白为什么。在其他示例中发现的是使用力矩,但仍然不应丢失错误。我在这里错过了什么?
'-' is an invalid end of a number. Expected a delimiter.
在引号中加上变量,以便将替换的值识别为字符串,而不是数字:
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"ticket": [
"The ticket field is required."
],
"$.DateCreated": [
"'-' is an invalid end of a number. Expected a delimiter. Path: $.DateCreated | LineNumber: 4 | BytePositionInLine: 23."
]
},
"traceId": "00-9949efdfca1190467313ca7436a54091-4b118077b8f84d1f-00"
}