{"record":{"id":"2fd773dcd00a9dce","repo":"RocketChat/Rocket.Chat","slug":"param-params-teams-key-must-be-an-array","errorCode":null,"errorMessage":"Param ${params.teams.key} must be an array","messagePattern":"Param (.+?) must be an array","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/api/v1/channels.ts","lineNumber":1031,"sourceCode":"\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>;\n\t\treadOnly?: boolean;\n\t\texcludeSelf?: boolean;\n\t},\n): Promise<{ channel: IRoom }> {\n\tconst readOnly = typeof params.readOnly !== 'undefined' ? params.readOnly : false;\n\tconst id = await createChannelMethod(\n\t\tuserId,\n\t\tparams.name || '',","sourceCodeStart":1013,"sourceCodeEnd":1049,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/e4b8178b205510181a96ceefee043d0abcd13e5a/apps/meteor/server/api/v1/channels.ts#L1013-L1049","documentation":"Validation error from POST channels.create: the optional teams parameter was provided but is not an array. teams must be an array of team identifiers to add the new channel to; a single team ID string or an object fails this check (unlike the other messages, this one interpolates the key without quotes).","triggerScenarios":"POST /api/v1/channels.create with teams: \"teamId123\" instead of teams: [\"teamId123\"], or teams: {teamId: true} from a checkbox-style form payload.","commonSituations":"Adding a channel to exactly one team and skipping the array wrapper; client serializers collapsing single-element arrays; confusing the teams array-of-IDs with the teamId single-ID parameter used for creating inside a team.","solutions":["Wrap team IDs in an array: teams: [\"teamId123\"]","Prefer the dedicated teamId parameter when creating a channel inside one team via the teams API semantics — check the endpoint docs for which is expected","Omit teams when the channel should not belong to any team"],"exampleFix":"// before\n{ \"name\": \"dev-talk\", \"teams\": \"teamId123\" }\n\n// after\n{ \"name\": \"dev-talk\", \"teams\": [\"teamId123\"] }","handlingStrategy":"type-guard","validationCode":"if (body.teams !== undefined && !Array.isArray(body.teams)) {\n  body.teams = [String(body.teams)];\n}","typeGuard":"const isTeamsArray = (t: unknown): t is string[] =>\n  t === undefined || Array.isArray(t);","tryCatchPattern":"try { await POST('/api/v1/channels.create', body); } catch (e) {\n  if (/teams.*must be an array/.test(e.message)) { /* wrap single ID in array, retry */ }\n}","preventionTips":["Always wrap team IDs in an array even for a single team","Do not confuse the teams array parameter with the singular teamId parameter"],"tags":["rest-api","channels","teams","validation","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"}