RocketChat/Rocket.Chat · error · Error
The "end" query parameter must be a valid date.
Error message
The "end" query parameter must be a valid date.
What it means
checkDates validates the moment-parsed end query parameter on every livechat/analytics/dashboards/* route; if end is missing, empty, or unparseable, this error is thrown before the report runs. start is checked first, so a bad start masks a bad end.
Source
Thrown at apps/meteor/ee/server/api/v1/omnichannel/reports.ts:20
import type { Moment } from 'moment';
import moment from 'moment';
import {
findAllConversationsBySourceCached,
findAllConversationsByStatusCached,
findAllConversationsByDepartmentCached,
findAllConversationsByTagsCached,
findAllConversationsByAgentsCached,
} from './lib/dashboards';
import { API } from '../../../../../server/api';
import { restrictQuery } from '../../../lib/omnichannel/restrictQuery';
const checkDates = (start: Moment, end: Moment) => {
if (!start.isValid()) {
throw new Error('The "start" query parameter must be a valid date.');
}
if (!end.isValid()) {
throw new Error('The "end" query parameter must be a valid date.');
}
// Check dates are no more than 1 year apart using moment
// 1.01 === "we allow to pass year by some hours/days"
if (moment(end).startOf('day').diff(moment(start).startOf('day'), 'year', true) > 1.01) {
throw new Error('The "start" and "end" query parameters must be less than 1 year apart.');
}
if (start.isAfter(end)) {
throw new Error('The "start" query parameter must be before the "end" query parameter.');
}
};
API.v1.addRoute(
'livechat/analytics/dashboards/conversations-by-source',
{
authRequired: true,
permissionsRequired: ['view-livechat-reports'],
validateParams: isGETDashboardConversationsByType,View on GitHub (pinned to b2c16d5842)
Solutions
- Send end as ISO 8601, e.g. 2024-12-31T23:59:59.999Z.
- Make end required in your client validation and never let it serialize as undefined/empty.
- If the intent is 'up to now', explicitly set end to the current time in ISO format.
Example fix
// before
api.get(url, { params: { start: '2024-01-01', end: undefined } });
// after
api.get(url, { params: { start: '2024-01-01', end: new Date().toISOString() } }); Defensive patterns
Strategy: validation
Validate before calling
const isIsoDate = (v: string | undefined): v is string => !!v && !Number.isNaN(Date.parse(v));
if (!isIsoDate(end)) end = new Date().toISOString(); // default 'up to now'
if (!isIsoDate(start)) throw new Error('start must be a valid ISO 8601 date');
await api.get(url, { params: { start, end } }); Try / catch
try {
await api.get(url, { params: { start, end } });
} catch (e) {
if (e?.response?.data?.error === 'The "end" query parameter must be a valid date.') {
// fill/normalize end (e.g. now) and retry once
} else throw e;
} Prevention
- Never let end serialize as undefined or empty string.
- Default end to 'now' explicitly in report clients.
- Check start first — a bad start masks a bad end.
When it happens
Trigger: GET /api/v1/livechat/analytics/dashboards/conversations-by-status?start=2024-01-01&end= (or end omitted, or end=whenever), leaving moment(end).isValid() false.
Common situations: Date-range pickers that submit an empty 'to' field; URL builders that drop falsy params; end computed from an undefined variable serialized as the string 'undefined'.
Related errors
- The "start" query parameter must be a valid date.
- The "start" and "end" query parameters must be less than 1 y
- The "start" query parameter must be before the "end" query p
- The "${property}.start" query parameter must be a valid date
- The "${property}.end" query parameter must be a valid date.
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/cf25a338ed8d9737.
Report an issue: GitHub.