RocketChat/Rocket.Chat · error · Meteor.Error

error-lastUpdate-param-invalid

error-lastUpdate-param-invalid

Error message

The "lastUpdate" query parameter must be a valid date

What it means

Thrown by GET chat.syncMessages when lastUpdate is supplied but Date.parse(lastUpdate) returns NaN — i.e. the value is not a parseable date string. Checked at chat.ts:722. The endpoint expects an ISO-8601 timestamp.

Source

Thrown at apps/meteor/server/api/v1/chat.ts:723

					additionalProperties: false,
				}),
				400: validateBadRequestErrorResponse,
				401: validateUnauthorizedErrorResponse,
			},
		},
		async function action() {
			const { roomId, lastUpdate, fromTs, count, next, previous, type } = this.queryParams;

			if (!roomId) {
				throw new Meteor.Error('error-param-required', 'The required "roomId" query param is missing');
			}

			if (!lastUpdate && !type) {
				throw new Meteor.Error('error-param-required', 'The "type" or "lastUpdate" parameters must be provided');
			}

			if (lastUpdate && isNaN(Date.parse(lastUpdate))) {
				throw new Meteor.Error('error-lastUpdate-param-invalid', 'The "lastUpdate" query parameter must be a valid date');
			}

			const getMessagesQuery = {
				...(lastUpdate && { lastUpdate: new Date(lastUpdate) }),
				...(fromTs && { fromTs: new Date(fromTs) }),
				...(next && { next }),
				...(previous && { previous }),
				...(count && { count }),
				...(type && { type }),
			};

			const result = await getMessageHistory(roomId, this.userId, getMessagesQuery);

			if (!result) {
				return API.v1.failure();
			}

			return API.v1.success({

View on GitHub (pinned to f9d3ec372b)

Solutions

  1. Send lastUpdate as a full ISO-8601 UTC string ending in 'Z', e.g. 2024-06-01T00:00:00.000Z.
  2. Generate it with new Date().toISOString() on the client.
  3. URL-encode the value so colons/periods survive transit.

Example fix

// before
GET /api/v1/chat.syncMessages?roomId=GENERAL&lastUpdate=1717200000
// after
GET /api/v1/chat.syncMessages?roomId=GENERAL&lastUpdate=2024-06-01T00:00:00.000Z
Defensive patterns

Strategy: validation

Validate before calling

function toIsoDate(value: string | number | Date): string {
  const d = value instanceof Date ? value : new Date(value);
  if (isNaN(d.getTime())) {
    throw new Error('lastUpdate must be a valid date; got: ' + String(value));
  }
  return d.toISOString();
}

u.searchParams.set('lastUpdate', toIsoDate(clientLastSync));

Type guard

const isValidIsoDate = (s: unknown): boolean =>
  typeof s === 'string' && !isNaN(Date.parse(s));

Try / catch

try {
  await GET(syncUrl);
} catch (e) {
  if ((e as any)?.error === 'error-lastUpdate-param-invalid') {
    // reset cursor to a known-good ISO value and retry once
  }
  throw e;
}

Prevention

When it happens

Trigger: Passing lastUpdate as a Unix epoch number, a locale-formatted string ('06/01/2024'), a relative token ('now'), or a malformed ISO string; or URL-encoding that mangles the timezone designator.

Common situations: Client serializing a Date with a non-ISO formatter; passing milliseconds since epoch; copy-paste truncating the 'Z' suffix; timezone offset like '+00:00' stripped by an intermediary.

Related errors


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