{"record":{"id":"01a55ec7c8ada3fb","repo":"RocketChat/Rocket.Chat","slug":"invalid-custom-fields-01a55e","errorCode":null,"errorMessage":"Invalid custom fields","messagePattern":"Invalid custom fields","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/messaging/validateCustomMessageFields.ts","lineNumber":40,"sourceCode":"\tcustomFields,\n\tmessageCustomFieldsEnabled,\n\tmessageCustomFields,\n}: {\n\tcustomFields: Record<string, any>;\n\tmessageCustomFieldsEnabled: boolean;\n\tmessageCustomFields: string;\n}) => {\n\t// get the json schema for the custom fields of the message and validate it using ajv\n\t// if the validation fails, throw an error\n\t// if there are no custom fields, the message object remains unchanged\n\n\tif (messageCustomFieldsEnabled !== true) {\n\t\tthrow new Error('Custom fields not enabled');\n\t}\n\n\tconst validate = customFieldsValidate(messageCustomFields);\n\tif (!validate(customFields)) {\n\t\tthrow new Error('Invalid custom fields');\n\t}\n};\n","sourceCodeStart":22,"sourceCodeEnd":43,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/messaging/validateCustomMessageFields.ts#L22-L43","documentation":"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.","triggerScenarios":"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.","commonSituations":"Client and workspace schema drifting apart after admins edit the setting; integrations sending extra metadata keys; renamed fields after a schema update.","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"],"exampleFix":"// before - schema declares ticketId as string only\nawait sendMessage(user, { ...message, customFields: { ticketId: 42, extra: 'x' } }, room);\n\n// after - match declared keys and types\ncustomFields: { ticketId: '42' }","handlingStrategy":"validation","validationCode":"// Pre-validate with the same schema the server compiles\nconst validate = ajv.compile({ ...workspaceCustomFieldsSchema, type: 'object', additionalProperties: false });\nif (!validate(customFields)) {\n  return reportFieldErrors(validate.errors);\n}\nawait sendMessage(user, { ...message, customFields }, room);","typeGuard":"const matchesCustomFieldsSchema = (fields: Record<string, unknown>): boolean => {\n  const declared = Object.keys(workspaceSchema.properties || {});\n  return Object.keys(fields).every((k) => declared.includes(k));\n};","tryCatchPattern":"try {\n  await sendMessage(user, { ...message, customFields }, room);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Invalid custom fields') {\n    showFieldValidationErrors(customFields); // tell the user which keys/types are wrong\n  }\n}","preventionTips":["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"],"tags":["custom-fields","schema-validation","ajv","messaging"],"backgroundTag":"schema-validation-failed","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}