Search code examples
node.jsloopback

Loopback Api Explorer Create Error: Invalid Date


I´m using the API explorer of loopback to create a model with the following parameters:

{
  "name": "string",
  "last_name": "string",
  "phone": 0,
  "is_invited": true,
  "realm": "string",
  "username": "string",
  "credentials": {},
  "challenges": {},
  "email": "string",
  "emailVerified": true,
  "status": "string",
  "created": "2016-06-03",
  "lastUpdated": "2016-06-03",
  "id": 0
}

However, The server is always returning a 500 invalid Date error:

{
  "error": {
    "name": "Error",
    "status": 500,
    "message": "Invalid date: Invalid Date",
    "stack": "Error: Invalid date: Invalid Date\n    at DateType }
}

This is my model for reference. It inherits the User model of Loopback.

{
  "name": "ExeboardUser",
  "base": "User",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "name": {
      "type": "string",
      "required": true
    },
    "last_name": {
      "type": "string"
    },
    "phone": {
      "type": "number",
      "required": true
    },
    "is_invited": {
      "type": "boolean",
      "required": true
    }
  },
  "validations": [],
  "relations": {
    "boards": {
      "type": "hasMany",
      "model": "Board",
      "foreignKey": "exeboardUserId",
      "through": "ExeboardUserBoard"
    }
  },
  "acls": [
    {
      "principalType": "ROLE",
      "principalId": "$everyone",
      "permission": "ALLOW",
      "property": "logout"
    }
  ],
  "methods": {

  }
}

Can anyone tell me what´s the problem with the date? I think it is correctly formated because it´s the default parameters that the explorer generates.


Solution

  • Don't know if you are interested in the answer, but I recently started working with loopback and got the same error as you, the date format that was accepted by the server is like this 2017-01-06T23:58:10.000Z

    Hope it helps someone.

    Ps.: if the date is not required by the model, don't even send it, not even with "null" or "" value, it will throw a 500 status error.