RocketChat/Rocket.Chat · error · Error

The "start" query parameter must be before the "end" query…

Error message

The "start" query parameter must be before the "end" query parameter.

What it means

checkDates requires start not to be after end (equal dates pass; only strictly-after fails). This is the last date check, running after validity and the 1-year span check, on every livechat/analytics/dashboards/* report route.

Solutions

  1. Order the pair before sending: send min(start,end) as start and max(start,end) as end.
  2. Check the UI binding for swapped from/to fields.
  3. Log the exact query string when dashboard requests fail to catch silent swaps.

Example fix

// before
api.get(url, { params: { start, end } }); // user picked end before start

// after
const [s, e] = start.isAfter(end) ? [end, start] : [start, end];
api.get(url, { params: { start: s.toISOString(), end: e.toISOString() } });
Defensive patterns

Strategy: validation

Validate before calling

const [s, e] = start.isAfter(end) ? [end, start] : [start, end];
await api.get(url, { params: { start: s.toISOString(), end: e.toISOString() } });

Prevention

When it happens

Trigger: GET .../conversations-by-source?start=2024-06-30&end=2024-01-01, or a client sending {from, to} in the wrong order after a refactor.

Common situations: Swapped query params; timezone conversion pushing a client's 'today' start past the server-parsed end; date pickers defaulting start to tomorrow; end truncated to midnight while start keeps a late-evening time.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18). Data as JSON: /api/errors/9158d10d1dbb8bd5. Report an issue: GitHub.

Appendix: source

Thrown at apps/meteor/ee/server/api/v1/omnichannel/reports.ts:29

} 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,
		license: ['livechat-enterprise'],
	},
	{
		async get() {
			const { start, end } = this.queryParams;

			const startDate = moment(start);
			const endDate = moment(end);

View on GitHub (pinned to b2c16d5842)