{"record":{"id":"52677945b6afaf24","repo":"RocketChat/Rocket.Chat","slug":"error-searchtext-param-not-provided","errorCode":"error-searchText-param-not-provided","errorMessage":"The required \"searchText\" query param is missing.","messagePattern":"The required \"searchText\" query param is missing\\.","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/api/v1/chat.ts","lineNumber":874,"sourceCode":"\t\t\t\t\t\tsuccess: { type: 'boolean', enum: [true] },\n\t\t\t\t\t},\n\t\t\t\t\trequired: ['messages', 'success'],\n\t\t\t\t\tadditionalProperties: false,\n\t\t\t\t}),\n\t\t\t\t400: validateBadRequestErrorResponse,\n\t\t\t\t401: validateUnauthorizedErrorResponse,\n\t\t\t},\n\t\t},\n\t\tasync function action() {\n\t\t\tconst { roomId, searchText } = this.queryParams;\n\t\t\tconst { offset, count } = await getPaginationItems(this.queryParams);\n\n\t\t\tif (!roomId) {\n\t\t\t\tthrow new Meteor.Error('error-roomId-param-not-provided', 'The required \"roomId\" query param is missing.');\n\t\t\t}\n\n\t\t\tif (!searchText) {\n\t\t\t\tthrow new Meteor.Error('error-searchText-param-not-provided', 'The required \"searchText\" query param is missing.');\n\t\t\t}\n\n\t\t\tconst searchResult = await messageSearch(this.userId, searchText, roomId, count, offset);\n\t\t\tif (searchResult === false) {\n\t\t\t\treturn API.v1.failure();\n\t\t\t}\n\t\t\tif (!searchResult.message) {\n\t\t\t\treturn API.v1.failure();\n\t\t\t}\n\t\t\tconst result = searchResult.message.docs;\n\n\t\t\treturn API.v1.success({\n\t\t\t\tmessages: await normalizeMessagesForUser(result, this.userId),\n\t\t\t});\n\t\t},\n\t)\n\t// The difference between `chat.postMessage` and `chat.sendMessage` is that `chat.sendMessage` allows\n\t// for passing a value for `_id` and the other one doesn't. Also, `chat.sendMessage` only sends it to","sourceCodeStart":856,"sourceCodeEnd":892,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/server/api/v1/chat.ts#L856-L892","documentation":"Thrown by GET chat.search when 'searchText' is missing. The endpoint cannot run an empty full-text query against the room; checked at chat.ts:875 right after the roomId guard.","triggerScenarios":"GET /api/v1/chat.search?roomId=GENERAL with no searchText; passing the term under 'query'/'q'/'term' instead. Note the endpoint returns API.v1.failure() (not success) when messageSearch itself yields no result, but a missing searchText throws before that.","commonSituations":"Submitting the search form before the user typed anything; client that clears the term before debounce fires; wrong param name from a generic search helper.","solutions":["Include a non-empty searchText: chat.search?roomId=GENERAL&searchText=deploy.","Guard the UI submit button so it is disabled while the query is empty.","Use the documented param name exactly — searchText, not q or query."],"exampleFix":"// before\nGET /api/v1/chat.search?roomId=GENERAL&q=deploy\n// after\nGET /api/v1/chat.search?roomId=GENERAL&searchText=deploy","handlingStrategy":"validation","validationCode":"function runSearch(roomId: string, term: string) {\n  const t = (term || '').trim();\n  if (!t) throw new Error('searchText is required and must be non-empty');\n  return GET(`/api/v1/chat.search?roomId=${encodeURIComponent(roomId)}&searchText=${encodeURIComponent(t)}`);\n}","typeGuard":"const hasSearchText = (q: { searchText?: string }): boolean =>\n  typeof q.searchText === 'string' && q.searchText.trim().length > 0;","tryCatchPattern":"try {\n  await GET(searchUrl);\n} catch (e) {\n  if ((e as any)?.error === 'error-searchText-param-not-provided') {\n    // user submitted an empty query — ignore rather than retry\n  }\n  throw e;\n}","preventionTips":["Disable the search submit control while the term is empty.","Debounce and skip dispatch when the trimmed term is empty.","Use the documented param name 'searchText', not 'q'."],"tags":["api","rest","validation","query-params","search","chat"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}