{"record":{"id":"ce60b865e140c358","repo":"RocketChat/Rocket.Chat","slug":"the-start-and-end-query-parameters-must-be-les","errorCode":null,"errorMessage":"The \"start\" and \"end\" query parameters must be less than 1 year apart.","messagePattern":"The \"start\" and \"end\" query parameters must be less than 1 year apart\\.","errorType":"exception","errorClass":"Error","httpStatus":400,"severity":"error","filePath":"apps/meteor/ee/server/api/v1/omnichannel/reports.ts","lineNumber":25,"sourceCode":"\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{\n\t\tauthRequired: true,\n\t\tpermissionsRequired: ['view-livechat-reports'],\n\t\tvalidateParams: isGETDashboardConversationsByType,\n\t\tlicense: ['livechat-enterprise'],\n\t},\n\t{\n\t\tasync get() {\n\t\t\tconst { start, end } = this.queryParams;","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/ee/server/api/v1/omnichannel/reports.ts#L7-L43","documentation":"checkDates rejects dashboard report ranges whose day-level difference exceeds 1.01 years (moment(end).startOf('day').diff(moment(start).startOf('day'), 'year', true) > 1.01; the 1.01 tolerance absorbs leap days, per the code comment). These cached dashboard endpoints only serve windows of roughly one year.","triggerScenarios":"GET .../conversations-by-source?start=2020-01-01&end=2024-01-01 — any range longer than about one year plus a few days fails this check.","commonSituations":"Year-over-year or 'all time' dashboards feeding the endpoint directly; a default end=now() paired with a fixed historical start; annual reports requested in a single call.","solutions":["Split the request into consecutive windows of at most 1 year and merge results client-side.","Clamp start to end minus 1 year when a rolling window is acceptable.","Keep start/end within the same or adjacent years for the built-in dashboards."],"exampleFix":"// before\nconst res = await api.get(url, { params: { start: '2021-01-01', end: '2024-01-01' } });\n\n// after\nconst windows = splitByYear('2021-01-01', '2024-01-01'); // chunks of <= 1 year\nconst res = (await Promise.all(windows.map(({ start, end }) => api.get(url, { params: { start, end } }))))\n  .flatMap((r) => r.items ?? []);","handlingStrategy":"validation","validationCode":"const startM = moment(start).startOf('day');\nconst endM = moment(end).startOf('day');\nif (endM.diff(startM, 'year', true) > 1.01) {\n  throw new Error('Range too wide: split into windows of at most 1 year');\n}\nawait api.get(url, { params: { start, end } });","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Mirror the server rule client-side: day-level diff in years must be <= 1.01.","Build report clients that page through time in <= 1-year windows.","Don't offer 'all time' options that map to a single request."],"tags":["omnichannel","analytics","date-range","rest-api","momentjs"],"backgroundTag":"invalid-date-range","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"}