{"record":{"id":"af6694daf7873ae6","repo":"RocketChat/Rocket.Chat","slug":"error-lastupdate-param-invalid","errorCode":"error-lastUpdate-param-invalid","errorMessage":"The \"lastUpdate\" query parameter must be a valid date","messagePattern":"The \"lastUpdate\" query parameter must be a valid date","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/api/v1/chat.ts","lineNumber":723,"sourceCode":"\t\t\t\t\tadditionalProperties: false,\n\t\t\t\t}),\n\t\t\t\t400: validateBadRequestErrorResponse,\n\t\t\t\t401: validateUnauthorizedErrorResponse,\n\t\t\t},\n\t\t},\n\t\tasync function action() {\n\t\t\tconst { roomId, lastUpdate, fromTs, count, next, previous, type } = this.queryParams;\n\n\t\t\tif (!roomId) {\n\t\t\t\tthrow new Meteor.Error('error-param-required', 'The required \"roomId\" query param is missing');\n\t\t\t}\n\n\t\t\tif (!lastUpdate && !type) {\n\t\t\t\tthrow new Meteor.Error('error-param-required', 'The \"type\" or \"lastUpdate\" parameters must be provided');\n\t\t\t}\n\n\t\t\tif (lastUpdate && isNaN(Date.parse(lastUpdate))) {\n\t\t\t\tthrow new Meteor.Error('error-lastUpdate-param-invalid', 'The \"lastUpdate\" query parameter must be a valid date');\n\t\t\t}\n\n\t\t\tconst getMessagesQuery = {\n\t\t\t\t...(lastUpdate && { lastUpdate: new Date(lastUpdate) }),\n\t\t\t\t...(fromTs && { fromTs: new Date(fromTs) }),\n\t\t\t\t...(next && { next }),\n\t\t\t\t...(previous && { previous }),\n\t\t\t\t...(count && { count }),\n\t\t\t\t...(type && { type }),\n\t\t\t};\n\n\t\t\tconst result = await getMessageHistory(roomId, this.userId, getMessagesQuery);\n\n\t\t\tif (!result) {\n\t\t\t\treturn API.v1.failure();\n\t\t\t}\n\n\t\t\treturn API.v1.success({","sourceCodeStart":705,"sourceCodeEnd":741,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/server/api/v1/chat.ts#L705-L741","documentation":"Thrown by GET chat.syncMessages when lastUpdate is supplied but Date.parse(lastUpdate) returns NaN — i.e. the value is not a parseable date string. Checked at chat.ts:722. The endpoint expects an ISO-8601 timestamp.","triggerScenarios":"Passing lastUpdate as a Unix epoch number, a locale-formatted string ('06/01/2024'), a relative token ('now'), or a malformed ISO string; or URL-encoding that mangles the timezone designator.","commonSituations":"Client serializing a Date with a non-ISO formatter; passing milliseconds since epoch; copy-paste truncating the 'Z' suffix; timezone offset like '+00:00' stripped by an intermediary.","solutions":["Send lastUpdate as a full ISO-8601 UTC string ending in 'Z', e.g. 2024-06-01T00:00:00.000Z.","Generate it with new Date().toISOString() on the client.","URL-encode the value so colons/periods survive transit."],"exampleFix":"// before\nGET /api/v1/chat.syncMessages?roomId=GENERAL&lastUpdate=1717200000\n// after\nGET /api/v1/chat.syncMessages?roomId=GENERAL&lastUpdate=2024-06-01T00:00:00.000Z","handlingStrategy":"validation","validationCode":"function toIsoDate(value: string | number | Date): string {\n  const d = value instanceof Date ? value : new Date(value);\n  if (isNaN(d.getTime())) {\n    throw new Error('lastUpdate must be a valid date; got: ' + String(value));\n  }\n  return d.toISOString();\n}\n\nu.searchParams.set('lastUpdate', toIsoDate(clientLastSync));","typeGuard":"const isValidIsoDate = (s: unknown): boolean =>\n  typeof s === 'string' && !isNaN(Date.parse(s));","tryCatchPattern":"try {\n  await GET(syncUrl);\n} catch (e) {\n  if ((e as any)?.error === 'error-lastUpdate-param-invalid') {\n    // reset cursor to a known-good ISO value and retry once\n  }\n  throw e;\n}","preventionTips":["Always serialize dates with toISOString().","URL-encode the timestamp to preserve colons and the 'Z' suffix.","Never pass a Unix epoch number as lastUpdate."],"tags":["api","rest","validation","query-params","date","chat","sync"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}