RocketChat/Rocket.Chat · error · Error

The "start" and "end" query parameters must be less than 1…

Error message

The "start" and "end" query parameters must be less than 1 year apart.

What it means

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.

Solutions

  1. Split the request into consecutive windows of at most 1 year and merge results client-side.
  2. Clamp start to end minus 1 year when a rolling window is acceptable.
  3. Keep start/end within the same or adjacent years for the built-in dashboards.

Example fix

// before
const res = await api.get(url, { params: { start: '2021-01-01', end: '2024-01-01' } });

// after
const windows = splitByYear('2021-01-01', '2024-01-01'); // chunks of <= 1 year
const res = (await Promise.all(windows.map(({ start, end }) => api.get(url, { params: { start, end } }))))
  .flatMap((r) => r.items ?? []);
Defensive patterns

Strategy: validation

Validate before calling

const startM = moment(start).startOf('day');
const endM = moment(end).startOf('day');
if (endM.diff(startM, 'year', true) > 1.01) {
  throw new Error('Range too wide: split into windows of at most 1 year');
}
await api.get(url, { params: { start, end } });

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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

Appendix: source

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

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

View on GitHub (pinned to b2c16d5842)