{"record":{"id":"f7ecd60410da0161","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-recipient","errorCode":"error-invalid-recipient","errorMessage":"error-invalid-recipient","messagePattern":"error-invalid-recipient","errorType":"exception","errorClass":"Meteor.Error","httpStatus":400,"severity":"error","filePath":"apps/meteor/server/api/v1/rooms.ts","lineNumber":1058,"sourceCode":"\t\t\t}\n\n\t\t\tvoid dataExport.sendFile(\n\t\t\t\t{\n\t\t\t\t\trid,\n\t\t\t\t\tformat,\n\t\t\t\t\tdateFrom: convertedDateFrom,\n\t\t\t\t\tdateTo: convertedDateTo,\n\t\t\t\t},\n\t\t\t\tuser,\n\t\t\t);\n\t\t\treturn API.v1.success();\n\t\t}\n\n\t\tif (type === 'email') {\n\t\t\tconst { toUsers, toEmails, subject, messages } = this.bodyParams;\n\n\t\t\tif ((!toUsers || toUsers.length === 0) && (!toEmails || toEmails.length === 0)) {\n\t\t\t\tthrow new Meteor.Error('error-invalid-recipient');\n\t\t\t}\n\n\t\t\tconst result = await dataExport.sendViaEmail(\n\t\t\t\t{\n\t\t\t\t\trid,\n\t\t\t\t\ttoUsers: (toUsers as string[]) || [],\n\t\t\t\t\ttoEmails: toEmails || [],\n\t\t\t\t\tsubject: subject || '',\n\t\t\t\t\tmessages: messages || [],\n\t\t\t\t\tlanguage: user.language || 'en',\n\t\t\t\t},\n\t\t\t\tuser,\n\t\t\t);\n\n\t\t\treturn API.v1.success(result);\n\t\t}\n\n\t\treturn API.v1.failure();","sourceCodeStart":1040,"sourceCodeEnd":1076,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/e4b8178b205510181a96ceefee043d0abcd13e5a/apps/meteor/server/api/v1/rooms.ts#L1040-L1076","documentation":"Thrown by POST /api/v1/rooms.export with type 'email' when both toUsers and toEmails are absent or empty arrays: the export has no recipient. The check runs before dataExport.sendViaEmail, and the error carries only the code 'error-invalid-recipient' with no message. At least one username in toUsers or one address in toEmails is required.","triggerScenarios":"POST rooms.export type 'email' with neither toUsers nor toEmails in the body; sending toUsers: [] and toEmails: []; a form where the recipient field was optional client-side but is required server-side.","commonSituations":"Email-export UIs letting users submit with an empty recipient box; API wrappers defaulting both fields to empty arrays; batch jobs templating the body without filling recipients.","solutions":["Include toUsers (array of usernames) or toEmails (array of email addresses), non-empty","Make the recipient field mandatory in the client form before submit","Default the recipient to the requesting user when none is supplied"],"exampleFix":"// before\nawait sdk.post('rooms.export', { rid, type: 'email', subject: 'chat log' }); // no recipients\n\n// after\nawait sdk.post('rooms.export', { rid, type: 'email', toUsers: ['alice'], subject: 'chat log', messages: [] });","handlingStrategy":"validation","validationCode":"if (!toUsers?.length && !toEmails?.length) throw new Error('provide toUsers (usernames) or toEmails (addresses)');","typeGuard":null,"tryCatchPattern":"try {\n  await sdk.post('rooms.export', { rid, type: 'email', toUsers, toEmails, subject, messages });\n} catch (e: any) {\n  if (e?.response?.data?.errorType === 'error-invalid-recipient') {\n    return sdk.post('rooms.export', { rid, type: 'email', toUsers: [requester], subject, messages });\n  }\n  throw e;\n}","preventionTips":["Make the recipient field required in email-export forms","Default recipients to the requesting user in API wrappers","Validate arrays are non-empty before templating request bodies"],"tags":["rooms","export","email","validation"],"backgroundTag":"missing-recipient","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"}