{"record":{"id":"fdbceefac676e6a4","repo":"RocketChat/Rocket.Chat","slug":"the-start-query-parameter-must-be-a-valid-date","errorCode":null,"errorMessage":"The \"start\" query parameter must be a valid date.","messagePattern":"The \"start\" query parameter must be a valid date\\.","errorType":"exception","errorClass":"Error","httpStatus":400,"severity":"error","filePath":"apps/meteor/ee/server/api/v1/omnichannel/reports.ts","lineNumber":17,"sourceCode":"import { isGETDashboardConversationsByType } from '@rocket.chat/rest-typings';\nimport type { Moment } from 'moment';\nimport moment from 'moment';\n\nimport {\n\tfindAllConversationsBySourceCached,\n\tfindAllConversationsByStatusCached,\n\tfindAllConversationsByDepartmentCached,\n\tfindAllConversationsByTagsCached,\n\tfindAllConversationsByAgentsCached,\n} from './lib/dashboards';\nimport { API } from '../../../../../server/api';\nimport { restrictQuery } from '../../../lib/omnichannel/restrictQuery';\n\nconst checkDates = (start: Moment, end: Moment) => {\n\tif (!start.isValid()) {\n\t\tthrow new Error('The \"start\" query parameter must be a valid date.');\n\t}\n\tif (!end.isValid()) {\n\t\tthrow new Error('The \"end\" query parameter must be a valid date.');\n\t}\n\t// Check dates are no more than 1 year apart using moment\n\t// 1.01 === \"we allow to pass year by some hours/days\"\n\tif (moment(end).startOf('day').diff(moment(start).startOf('day'), 'year', true) > 1.01) {\n\t\tthrow new Error('The \"start\" and \"end\" query parameters must be less than 1 year apart.');\n\t}\n\n\tif (start.isAfter(end)) {\n\t\tthrow new Error('The \"start\" query parameter must be before the \"end\" query parameter.');\n\t}\n};\n\nAPI.v1.addRoute(\n\t'livechat/analytics/dashboards/conversations-by-source',\n\t{","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/ee/server/api/v1/omnichannel/reports.ts#L1-L35","documentation":"Every GET livechat/analytics/dashboards/* report route (conversations-by-source, -status, -department, -tags, -agent, ...) runs checkDates(start, end) on the moment-parsed query params. If start cannot be parsed into a valid moment (missing, empty, or unrecognized format), this error is thrown before the cached aggregation runs.","triggerScenarios":"GET /api/v1/livechat/analytics/dashboards/conversations-by-source?start=abc&end=2024-01-01, or omitting start / sending an empty value, so moment(start).isValid() is false.","commonSituations":"Passing human dates ('yesterday', '01/02/2024' in an unexpected locale format); leaving the param out because the dashboard UI normally fills it; copy-pasted values with trailing spaces or smart quotes.","solutions":["Send start as ISO 8601, e.g. 2024-01-01T00:00:00.000Z or 2024-01-01.","Always include both start and end, non-empty.","Normalize dates client-side (moment/date-fns) before building the query string."],"exampleFix":"// before\napi.get('/v1/livechat/analytics/dashboards/conversations-by-source', { params: { start: 'yesterday', end } });\n\n// after\napi.get('/v1/livechat/analytics/dashboards/conversations-by-source', {\n  params: { start: moment(start).toISOString(), end: moment(end).toISOString() },\n});","handlingStrategy":"validation","validationCode":"const isIsoDate = (v: string | undefined): v is string => !!v && !Number.isNaN(Date.parse(v));\nif (!isIsoDate(start) || !isIsoDate(end)) {\n  throw new Error('start and end must be valid ISO 8601 dates');\n}\nawait api.get(url, { params: { start, end } });","typeGuard":null,"tryCatchPattern":"try {\n  await api.get(url, { params: { start, end } });\n} catch (e) {\n  if (e?.response?.data?.error === 'The \"start\" query parameter must be a valid date.') {\n    // normalize start to ISO 8601 and retry once\n  } else throw e;\n}","preventionTips":["Serialize dates with toISOString() before building query strings.","Make both bounds required in your client types.","Reject free-text date input in UIs feeding these reports."],"tags":["omnichannel","analytics","date-validation","rest-api","momentjs"],"backgroundTag":"invalid-date-format","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}