I'm having issues getting datetime into a db from post man API calls. What I have is a body that accepts the following:
POST Call in PostMan
HTTP://localhost:5000/api/ticket
Pre-Script
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
}
All seems fine and dandy but I'm getting an error of '-' is an invalid end of a number. Expected a delimiter.
I do not understand why. Found out in other examples are using moment but still should not throw an error. What am I missing here?
Error 400 Bad Request
{
"type": ".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"
}
I'm having issues getting datetime into a db from post man API calls. What I have is a body that accepts the following:
POST Call in PostMan
HTTP://localhost:5000/api/ticket
Pre-Script
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
}
All seems fine and dandy but I'm getting an error of '-' is an invalid end of a number. Expected a delimiter.
I do not understand why. Found out in other examples are using moment but still should not throw an error. What am I missing here?
Error 400 Bad Request
{
"type": "https://tools.ietf./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"
}
Share
Improve this question
asked Mar 12 at 21:45
DonDavid12DonDavid12
2091 silver badge11 bronze badges
1
- 1 You haven't posted any code related to the problem you're asking about. I'd guess that you need to reformat the ISO datetime into whatever format your database needs. Maybe you're doing that. We can't tell. You haven't even tagged the database you're using. – Tangentially Perpendicular Commented Mar 12 at 22:01
1 Answer
Reset to default 1enclose the variable in quotes so that the substituted value is recognized as a string and not as a number:
{
"TicketTitle": "Main Title",
"DateCreated": "{{timestamp}}",
"CreatedBy": "John Doe"
}