{"record":{"id":"ff1af3aabb2efa41","repo":"davila7/claude-code-templates","slug":"sessionid-and-message-are-required","errorCode":null,"errorMessage":"sessionId and message are required","messagePattern":"sessionId and message are required","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"cli-tool/src/claude-api-proxy.js","lineNumber":54,"sourceCode":"  setupRoutes() {\n    // Get active conversations/sessions\n    this.app.get('/api/sessions', async (req, res) => {\n      try {\n        const sessions = await this.getActiveSessions();\n        res.json({ sessions });\n      } catch (error) {\n        console.error('Error getting sessions:', error);\n        res.status(500).json({ error: error.message });\n      }\n    });\n    \n    // Send message to Claude (main endpoint)\n    this.app.post('/api/send-message', async (req, res) => {\n      try {\n        const { sessionId, message, projectPath } = req.body;\n        \n        if (!sessionId || !message) {\n          return res.status(400).json({ error: 'sessionId and message are required' });\n        }\n        \n        const result = await this.sendMessageToClaude(sessionId, message, projectPath);\n        res.json(result);\n        \n      } catch (error) {\n        console.error('Error sending message:', error);\n        res.status(500).json({ error: error.message });\n      }\n    });\n    \n    // Get conversation history\n    this.app.get('/api/conversation/:sessionId', async (req, res) => {\n      try {\n        const { sessionId } = req.params;\n        const conversation = await this.getConversationHistory(sessionId);\n        res.json({ conversation });\n      } catch (error) {","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/davila7/claude-code-templates/blob/a0851ed10c7c60463dac8cfaaca124cf32d5804d/cli-tool/src/claude-api-proxy.js#L36-L72","documentation":"HTTP 400 from the claude-api-proxy POST /api/send-message endpoint when the request body lacks sessionId or message (projectPath is optional). It's a plain required-field validation before the proxy attempts to spawn/talk to Claude.","triggerScenarios":"POST /api/send-message with a JSON body missing sessionId, missing message, or with either falsy (empty string / null); also when the body isn't parsed as JSON so both destructure to undefined.","commonSituations":"Client forgot to create/attach a session id before sending; sending form-encoded or text/plain body to an endpoint that expects req.body JSON (missing content-type: application/json); frontend race where the message input is empty but submit fired.","solutions":["Ensure the request has header Content-Type: application/json and a body like {\"sessionId\":\"...\",\"message\":\"...\"}","Create a session first (or reuse an existing session id) and include it in the payload","Trim/guard the message field client-side before enabling the send button","Check for accidental typos in field names (session_id vs sessionId)"],"exampleFix":"// before\nfetch('/api/send-message', { method: 'POST', body: JSON.stringify({ message }) });\n// after\nfetch('/api/send-message', {\n  method: 'POST',\n  headers: { 'Content-Type': 'application/json' },\n  body: JSON.stringify({ sessionId, message })\n});","handlingStrategy":"validation","validationCode":"if (!sessionId || !String(message).trim()) throw new Error('missing sessionId or message');\nawait fetch('/api/send-message', {\n  method: 'POST',\n  headers: { 'Content-Type': 'application/json' },\n  body: JSON.stringify({ sessionId, message: message.trim(), projectPath })\n});","typeGuard":"const isSendPayload = (b) =>\n  typeof b?.sessionId === 'string' && b.sessionId.length > 0 &&\n  typeof b?.message === 'string' && b.message.trim().length > 0;","tryCatchPattern":"catch (e) { if (e.status === 400) disableSendUntilFieldsValid(); else throw e; }","preventionTips":["Always send Content-Type: application/json","Disable submit until both fields are non-empty","Use exact field names sessionId/message"],"tags":["http-400","validation","required-fields","express"],"backgroundTag":"request-validation-failed","analyzedSha":"a0851ed10c7c60463dac8cfaaca124cf32d5804d","analyzedAt":"2026-08-28T14:11:56.058Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}