datedatetimepostman

Invalid end of a number. Expects Delimiter


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.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"
}

Solution

  • enclose 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"
    }