RocketChat/Rocket.Chat · error · Error
Invalid custom fields
Error message
Invalid custom fields
What it means
When custom fields are enabled, the message's customFields object is validated against the ajv schema compiled from Message_CustomFields; a mismatch throws a plain Error 'Invalid custom fields'. Because the compiler forces additionalProperties: false, any key not declared in the setting's properties rejects the whole message, as do wrong types and missing required fields.
Source
Thrown at apps/meteor/server/lib/messaging/validateCustomMessageFields.ts:40
customFields,
messageCustomFieldsEnabled,
messageCustomFields,
}: {
customFields: Record<string, any>;
messageCustomFieldsEnabled: boolean;
messageCustomFields: string;
}) => {
// get the json schema for the custom fields of the message and validate it using ajv
// if the validation fails, throw an error
// if there are no custom fields, the message object remains unchanged
if (messageCustomFieldsEnabled !== true) {
throw new Error('Custom fields not enabled');
}
const validate = customFieldsValidate(messageCustomFields);
if (!validate(customFields)) {
throw new Error('Invalid custom fields');
}
};
View on GitHub (pinned to b2c16d5842)
Solutions
- Align the payload with the configured schema: only declared keys with correct types
- Update Message_CustomFields to declare new keys before sending them
- Pre-validate customFields with the same schema client-side before calling the send API
Example fix
// before - schema declares ticketId as string only
await sendMessage(user, { ...message, customFields: { ticketId: 42, extra: 'x' } }, room);
// after - match declared keys and types
customFields: { ticketId: '42' } Defensive patterns
Strategy: validation
Validate before calling
// Pre-validate with the same schema the server compiles
const validate = ajv.compile({ ...workspaceCustomFieldsSchema, type: 'object', additionalProperties: false });
if (!validate(customFields)) {
return reportFieldErrors(validate.errors);
}
await sendMessage(user, { ...message, customFields }, room); Type guard
const matchesCustomFieldsSchema = (fields: Record<string, unknown>): boolean => {
const declared = Object.keys(workspaceSchema.properties || {});
return Object.keys(fields).every((k) => declared.includes(k));
}; Try / catch
try {
await sendMessage(user, { ...message, customFields }, room);
} catch (e) {
if (e instanceof Error && e.message === 'Invalid custom fields') {
showFieldValidationErrors(customFields); // tell the user which keys/types are wrong
}
} Prevention
- Keep the client-side schema in lockstep with the workspace's Message_CustomFields setting
- Send only declared keys - additionalProperties is false server-side
- Surface ajv-style field errors in forms instead of raw send failures
When it happens
Trigger: sendMessage/updateMessage with customFields containing keys not declared in the Message_CustomFields schema (rejected by additionalProperties: false), values of the wrong type, or missing required properties.
Common situations: Client and workspace schema drifting apart after admins edit the setting; integrations sending extra metadata keys; renamed fields after a schema update.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Invalid custom fields config
- Custom fields not enabled
- invalid-token
- Invalid response from Rocket.Chat Cloud
- failed type validation
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/01a55ec7c8ada3fb.
Report an issue: GitHub.