{"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":727,"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":709,"sourceCodeEnd":745,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/e4b8178b205510181a96ceefee043d0abcd13e5a/apps/meteor/server/api/v1/chat.ts#L709-L745","documentation":"Thrown by GET chat.syncMessages (apps/meteor/server/api/v1/chat.ts:723) when lastUpdate is provided but Date.parse(lastUpdate) is NaN, with error-lastUpdate-param-invalid. The handler will construct new Date(lastUpdate) for the Mongo query, so an unparseable timestamp is rejected up front. The query schema types lastUpdate as a plain string, so format errors are caught here, not by schema.","triggerScenarios":"GET /api/v1/chat.syncMessages?roomId=...&lastUpdate=<bad> where <bad> is a non-ISO string: '2024/05/01' (slashes), '01-05-2024', a Unix epoch number passed as string ('1714521600'), 'now', or a locale-formatted date. Only ISO 8601 ('2024-05-01T00:00:00Z' or '2024-05-01') parses reliably.","commonSituations":"Passing seconds/milliseconds since epoch instead of a date string; using the local Date.toString() output (locale-dependent); URL-encoding bugs that mangle the '+' timezone offset into a space (e.g. 2024-05-01T00:00:00+00:00 sent unencoded); dates built with custom formatters.","solutions":["Send lastUpdate as strict ISO 8601 UTC: new Date().toISOString() → '2024-05-01T12:34:56.789Z'.","If you hold a epoch number, convert first: new Date(epochMs).toISOString().","URL-encode the param (encodeURIComponent) so timezone offsets and colons survive transport.","Avoid date-fns/moment default formats that emit slashes or ambiguous orders; test with Date.parse() client-side before sending."],"exampleFix":"// before\nrc.get('/api/v1/chat.syncMessages', { params: { roomId, lastUpdate: String(Date.now()) } }); // epoch string -> NaN parse\n\n// after\nrc.get('/api/v1/chat.syncMessages', { params: { roomId, lastUpdate: new Date().toISOString() } });","handlingStrategy":"validation","validationCode":"const isValidRocketDate = (s: string) => !Number.isNaN(Date.parse(s));\nconst lastUpdate = new Date(sinceMs).toISOString();\nif (!isValidRocketDate(lastUpdate)) throw new Error('lastUpdate must be ISO 8601');\nawait rc.get('/api/v1/chat.syncMessages', { params: { roomId, lastUpdate } });","typeGuard":"const isIsoDateString = (s: unknown): s is string =>\n  typeof s === 'string' && !Number.isNaN(Date.parse(s));","tryCatchPattern":"try {\n  await rc.get('/api/v1/chat.syncMessages', { params: { roomId, lastUpdate } });\n} catch (e) {\n  if (e?.errorType === 'error-lastUpdate-param-invalid') {\n    await retryWithIso(); // re-send lastUpdate = new Date().toISOString()\n  } else throw e;\n}","preventionTips":["Always serialize dates with toISOString(); never send epoch numbers or locale formats.","Encode query params (encodeURIComponent) so '+' in timezone offsets does not degrade to a space."],"tags":["rocket-chat","rest-api","sync","date-format","invalid-parameter","chat-syncmessages"],"backgroundTag":"invalid-date-format","analyzedSha":"e4b8178b205510181a96ceefee043d0abcd13e5a","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}