RocketChat/Rocket.Chat · error · Error

invalid-data

Error message

invalid-data

What it means

Thrown by POST /api/v1/livechat/room.survey when the request body's data array produces an empty updateData: every entry failed the filter (name must be a configured survey item AND value a configured survey value, or name must be exactly 'additionalFeedback'). The config was fine; the submitted answers matched nothing.

Solutions

  1. Fetch the definition first (GET livechat/config or the config embedded in the widget) and build the form from survey.items/survey.values
  2. Map answers to exact configured names/values, and include additionalFeedback verbatim as the free-text key
  3. Client-side: reject submission when every field is empty instead of posting an empty payload

Example fix

// before
postSurvey(rid, token, [
  { name: 'How satisfied were you?', value: 'very' }, // display name + label value
]);

// after
const { survey } = await getLivechatConfig();
postSurvey(rid, token, [
  { name: survey.items[0], value: survey.values[4] }, // exact configured name + value
  { name: 'additionalFeedback', value: comment },
]);
Defensive patterns

Strategy: validation

Validate before calling

const { survey } = await getLivechatConfig();
const valid = data.filter((item) =>
  (survey.items.includes(item.name) && survey.values.includes(item.value)) || item.name === 'additionalFeedback',
);
if (valid.length === 0) return warnUser('fill at least one field');
await postSurvey(rid, token, valid);

Type guard

function isSurveyItemValid(item, survey) {
  return (survey.items.includes(item.name) && survey.values.includes(item.value)) || item.name === 'additionalFeedback';
}

Try / catch

try { await postSurvey(rid, token, data); } catch (e) { if (e.message === 'invalid-data') { rebuildFormFromConfig(); return; } throw e; }

Prevention

When it happens

Trigger: Sending survey answers whose item names do not match config.survey.items (e.g. 'satisfaction' vs 'feedback'), whose values are outside config.survey.values (e.g. '6' on a 1–5 scale), sending an empty data array, or sending only unrecognized free-form keys.

Common situations: Custom survey UI hardcoded with item names/values that drifted from the admin-configured survey; client sending display labels instead of stored values; localizing the item names before submission.

Related errors


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

Appendix: source

Thrown at apps/meteor/server/api/v1/omnichannel/room.ts:272

			const room = await findRoom(token, rid);
			if (!room) {
				throw new Error('invalid-room');
			}

			const config = await settings();
			if (!config.survey?.items || !config.survey.values) {
				throw new Error('invalid-livechat-config');
			}

			const updateData: { [k: string]: string } = {};
			for (const item of data) {
				if ((config.survey.items.includes(item.name) && config.survey.values.includes(item.value)) || item.name === 'additionalFeedback') {
					updateData[item.name] = item.value;
				}
			}

			if (Object.keys(updateData).length === 0) {
				throw new Error('invalid-data');
			}

			if (!(await LivechatRooms.updateSurveyFeedbackById(room._id, updateData))) {
				return API.v1.failure();
			}

			return API.v1.success({ rid, data: updateData });
		},
	},
);

API.v1.addRoute(
	'livechat/room.forward',
	{ authRequired: true, permissionsRequired: ['view-l-room', 'transfer-livechat-guest'], validateParams: isLiveChatRoomForwardProps },
	{
		async post() {
			const transferData = this.bodyParams as typeof this.bodyParams & {
				transferredBy: TransferByData;

View on GitHub (pinned to b2c16d5842)