{"record":{"id":"e58a1f299e1c2eeb","repo":"RocketChat/Rocket.Chat","slug":"param-params-members-key-must-be-an-array-if","errorCode":null,"errorMessage":"Param \"${params.members.key}\" must be an array if provided","messagePattern":"Param \"(.+?)\" must be an array if provided","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/api/v1/channels.ts","lineNumber":1023,"sourceCode":"\tteams?: { key: string; value?: string[] };\n\tteamId?: { key: string; value?: string };\n}) {\n\tconst teamId = params.teamId?.value;\n\n\tconst team = teamId && (await Team.getInfoById(teamId));\n\tif (\n\t\t(!teamId && !(await hasPermissionAsync(params.user.value, 'create-c'))) ||\n\t\t(teamId && team && !(await hasPermissionAsync(params.user.value, 'create-team-channel', team.roomId)))\n\t) {\n\t\tthrow new Error('unauthorized');\n\t}\n\n\tif (!params.name?.value) {\n\t\tthrow new Error(`Param \"${params.name?.key}\" is required`);\n\t}\n\n\tif (params.members?.value && !Array.isArray(params.members.value)) {\n\t\tthrow new Error(`Param \"${params.members.key}\" must be an array if provided`);\n\t}\n\n\tif (params.customFields?.value && !(typeof params.customFields.value === 'object')) {\n\t\tthrow new Error(`Param \"${params.customFields.key}\" must be an object if provided`);\n\t}\n\n\tif (params.teams?.value && !Array.isArray(params.teams.value)) {\n\t\tthrow new Error(`Param ${params.teams.key} must be an array`);\n\t}\n}\n\nasync function createChannel(\n\tuserId: string,\n\tparams: {\n\t\tname?: string;\n\t\tmembers?: string[];\n\t\tcustomFields?: Record<string, any>;\n\t\textraData?: Record<string, any>;","sourceCodeStart":1005,"sourceCodeEnd":1041,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/e4b8178b205510181a96ceefee043d0abcd13e5a/apps/meteor/server/api/v1/channels.ts#L1005-L1041","documentation":"Validation error from POST channels.create: the optional members parameter was provided but is not an array. The API expects members to be a JSON array of usernames to invite on creation; sending a comma-separated string, a single string, or an object fails this check.","triggerScenarios":"POST /api/v1/channels.create with members: \"alice,bob\", members: \"alice\", or members: {\"0\":\"alice\"} instead of members: [\"alice\",\"bob\"].","commonSituations":"Joining a split string without .split(','); passing a single username for convenience; form data parsed as object instead of array; serialization library converting single-element arrays to scalars (common with PHP http_build_query or some XML->JSON paths).","solutions":["Send members as a JSON array of username strings: members: [\"alice\", \"bob\"]","When accepting free-text input client-side, split and trim: input.split(',').map(s => s.trim()).filter(Boolean)","Omit members entirely when there are none to invite — it is optional"],"exampleFix":"// before\n{ \"name\": \"dev-talk\", \"members\": \"alice,bob\" }\n\n// after\n{ \"name\": \"dev-talk\", \"members\": [\"alice\", \"bob\"] }","handlingStrategy":"type-guard","validationCode":"if (body.members !== undefined && !Array.isArray(body.members)) {\n  body.members = String(body.members).split(',').map((s) => s.trim()).filter(Boolean);\n}","typeGuard":"const isUsernameArray = (m: unknown): m is string[] =>\n  Array.isArray(m) && m.every((x) => typeof x === 'string');","tryCatchPattern":"try { await POST('/api/v1/channels.create', body); } catch (e) {\n  if (/must be an array if provided/.test(e.message)) { /* coerce members to array and retry */ }\n}","preventionTips":["Always send members as a JSON array of username strings","Split-and-trim comma input at the UI boundary, not on the server"],"tags":["rest-api","channels","validation","type-mismatch","rocket-chat"],"backgroundTag":"parameter-type-mismatch","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"}