{"record":{"id":"a2dcba76572c2b2b","repo":"RocketChat/Rocket.Chat","slug":"the-required-mid-body-param-is-missing","errorCode":null,"errorMessage":"The required \"mid\" body param is missing.","messagePattern":"The required \"mid\" body param is missing\\.","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/api/v1/chat.ts","lineNumber":485,"sourceCode":"\t\t\t\t401: validateUnauthorizedErrorResponse,\n\t\t\t\t200: ajv.compile<void>({\n\t\t\t\t\ttype: 'object',\n\t\t\t\t\tproperties: {\n\t\t\t\t\t\tsuccess: {\n\t\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\t\tenum: [true],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\trequired: ['success'],\n\t\t\t\t\tadditionalProperties: false,\n\t\t\t\t}),\n\t\t\t},\n\t\t},\n\t\tasync function action() {\n\t\t\tconst { mid } = this.bodyParams;\n\n\t\t\tif (!mid) {\n\t\t\t\tthrow new Meteor.Error('The required \"mid\" body param is missing.');\n\t\t\t}\n\n\t\t\tawait followMessage(this.user, { mid });\n\n\t\t\treturn API.v1.success();\n\t\t},\n\t)\n\t.post(\n\t\t'chat.unfollowMessage',\n\t\t{\n\t\t\tauthRequired: true,\n\t\t\tbody: isChatUnfollowMessageLocalProps,\n\t\t\tresponse: {\n\t\t\t\t400: validateBadRequestErrorResponse,\n\t\t\t\t401: validateUnauthorizedErrorResponse,\n\t\t\t\t200: ajv.compile<void>({\n\t\t\t\t\ttype: 'object',\n\t\t\t\t\tproperties: {","sourceCodeStart":467,"sourceCodeEnd":503,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/e4b8178b205510181a96ceefee043d0abcd13e5a/apps/meteor/server/api/v1/chat.ts#L467-L503","documentation":"Thrown by POST chat.followMessage (apps/meteor/server/api/v1/chat.ts:481) when this.bodyParams.mid is falsy before calling followMessage. Note it is a Meteor.Error with no error code - only the message text. On current servers the body schema (isChatFollowMessageLocalProps, requires mid with minLength 1) rejects a missing/empty mid first with a schema 400, so this throw is a legacy/defense-in-depth guard that mainly surfaces on older builds or when validation is bypassed.","triggerScenarios":"POST /api/v1/chat.followMessage with body lacking mid, with mid: \"\" or mid: null. On modern servers you usually get 'Body does not match schema' (400) instead; this exact message appears on servers predating body validation on this endpoint or when mid is explicitly undefined in crafted payloads.","commonSituations":"Integrations written against old Rocket.Chat versions (pre-schema-validation) re-surfacing after upgrades in reverse; JSON bodies built dynamically where mid is conditionally omitted; tests sending {} to probe validation behavior.","solutions":["Always send { \"mid\": \"<message id>\" } in the body - mid is required and must be non-empty.","Upgrade the server so missing params fail fast in schema validation with a clear 400 instead of reaching the handler.","If you maintain a client, validate the payload against the published ChatFollowMessage schema (mid: string, minLength 1) before sending.","On the client, treat both this message and 'Body does not match schema' as the same class: caller forgot mid."],"exampleFix":"// before\nawait rc.post('/api/v1/chat.followMessage', { }); // 400: mid required\n\n// after\nawait rc.post('/api/v1/chat.followMessage', { mid: messageId });","handlingStrategy":"validation","validationCode":"const isFollowPayload = (p: { mid?: unknown }): p is { mid: string } =>\n  typeof p.mid === 'string' && p.mid.length > 0;\nif (!isFollowPayload(payload)) throw new Error('mid is required');\nawait rc.post('/api/v1/chat.followMessage', payload);","typeGuard":"const isFollowPayload = (p: { mid?: unknown }): p is { mid: string } =>\n  typeof p.mid === 'string' && p.mid.length > 0;","tryCatchPattern":"try {\n  await rc.post('/api/v1/chat.followMessage', { mid });\n} catch (e) {\n  if (/\"mid\" body param is missing/i.test(e?.error ?? '') || e?.errorType === 'error-invalid-params') fixPayload();\n  else throw e;\n}","preventionTips":["Type the request body and validate mid (non-empty string) before sending.","mid is the thread's main message id - capture it when the follow action starts so unfollow can reuse it."],"tags":["rocket-chat","rest-api","threads","follow","missing-parameter","chat-followmessage"],"backgroundTag":"missing-required-argument","analyzedSha":"e4b8178b205510181a96ceefee043d0abcd13e5a","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}