date - Invalid end of a number. Expects Delimiter - Stack Overflow

I'm having issues getting datetime into a db from post man API calls. What I have is a body that a

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
Add a comment  | 

1 Answer 1

Reset to default 1

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744729093a4590357.html

相关推荐

  • date - Invalid end of a number. Expects Delimiter - Stack Overflow

    I'm having issues getting datetime into a db from post man API calls. What I have is a body that a

    1天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信