{"record":{"id":"d9d8a4b2939f5bcc","repo":"RocketChat/Rocket.Chat","slug":"error-token-param-not-provided","errorCode":null,"errorMessage":"error-token-param-not-provided","messagePattern":"error-token-param-not-provided","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/api/v1/omnichannel/message.ts","lineNumber":205,"sourceCode":"\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn API.v1.failure();\n\t\t},\n\t},\n);\n\nAPI.v1.addRoute(\n\t'livechat/messages.history/:rid',\n\t{ validateParams: isGETLivechatMessagesHistoryRidParams },\n\t{\n\t\tasync get() {\n\t\t\tconst { offset } = await getPaginationItems(this.queryParams);\n\t\t\tconst { token } = this.queryParams;\n\t\t\tconst { rid } = this.urlParams;\n\n\t\t\tif (!token) {\n\t\t\t\tthrow new Error('error-token-param-not-provided');\n\t\t\t}\n\n\t\t\tconst guest = await findGuest(token);\n\t\t\tif (!guest) {\n\t\t\t\tthrow new Error('invalid-token');\n\t\t\t}\n\n\t\t\tconst room = await findRoom(token, rid);\n\t\t\tif (!room) {\n\t\t\t\tthrow new Error('invalid-room');\n\t\t\t}\n\n\t\t\tlet ls = undefined;\n\t\t\tif (this.queryParams.ls) {\n\t\t\t\tls = new Date(this.queryParams.ls);\n\t\t\t}\n\n\t\t\tlet end = undefined;","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/server/api/v1/omnichannel/message.ts#L187-L223","documentation":"Thrown in the GET handler of 'livechat/messages.history/:rid' (message.ts:204-206) when the token query parameter is missing or falsy. Unlike POST/DELETE endpoints that read token from bodyParams, this GET endpoint reads from this.queryParams.token. The explicit check fires before findGuest is ever called.","triggerScenarios":"Calling GET /api/v1/livechat/messages.history/:rid without a token query parameter, or with an empty string value. Example: GET /livechat/messages.history/abc123 with no ?token=... appended.","commonSituations":"Developer forgot to append the token query param for the GET request; client SDK bug that omits query params for GET; URL encoding issue stripping the param; testing without providing credentials; using a POST-style body for a GET request.","solutions":["Add the token query parameter: GET /api/v1/livechat/messages.history/:rid?token=YOUR_VISITOR_TOKEN.","Ensure the token is URL-encoded if it contains special characters.","Verify your HTTP client attaches query params correctly for GET requests (not in the body)."],"exampleFix":"// before\nGET /api/v1/livechat/messages.history/abc123\n// throws 'error-token-param-not-provided'\n\n// after\nGET /api/v1/livechat/messages.history/abc123?token=visitor-token-here","handlingStrategy":"validation","validationCode":"// Ensure token is present before making the GET request\nif (!token || token.trim() === '') {\n  throw new Error('token query parameter is required for messages.history');\n}\nconst url = `/api/v1/livechat/messages.history/${rid}?token=${encodeURIComponent(token)}`;","typeGuard":null,"tryCatchPattern":"try {\n  const res = await fetch(`/livechat/messages.history/${rid}?token=${encodeURIComponent(token)}`);\n} catch (err) {\n  if (err.message === 'error-token-param-not-provided') {\n    // ensure token is set and URL-encoded before retrying\n    if (!token) token = await getVisitorToken();\n  }\n}","preventionTips":["Always construct GET request URLs with a URL builder that validates required query params.","Write a client wrapper that enforces token presence for all livechat visitor endpoints.","Use encodeURIComponent() on token values to avoid URL encoding issues."],"tags":["omnichannel","token","query-params","validation","messages"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}