while sending a post request on postman after session id is generated, it goes to catch block, and it shows error
Error: Missing required parameters: sessionId
at Object.getMissingParams (E:\Projects\ChatBot App\node_modules\ibm-cloud-sdk-core\lib\helper.js:116:11)
at AssistantV2.message (E:\Projects\ChatBot App\node_modules\ibm-watson\assistant\v2.js:217:50)
at E:\Projects\ChatBot App\routes\api\watson.js:44:41
at Layer.handle [as handle_request] (E:\Projects\ChatBot App\node_modules\express\lib\router\layer.js:95:5)
at next (E:\Projects\ChatBot App\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (E:\Projects\ChatBot App\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (E:\Projects\ChatBot App\node_modules\express\lib\router\layer.js:95:5)
at E:\Projects\ChatBot App\node_modules\express\lib\router\index.js:281:22
at Function.process_params (E:\Projects\ChatBot App\node_modules\express\lib\router\index.js:335:12)
at next (E:\Projects\ChatBot App\node_modules\express\lib\router\index.js:275:10)
the code is:
router.post('/message', async (req, res) => {
payload = {
assistantId: process.env.WA_ASSISTANT_ID,
sessionId: req.headers.session_id,
input: {
message_type: "text",
text: req.body.input,
},
};
try {
const message = await assistant.message(payload);
res.json(message["result"]);
} catch (err) {
res.send("There was an error processing your request.");
console.log(err);
}
});
Your screenshot of Postman shows that you added session_id as URL parameters. That would be for a GET request. You need to transfer the assistantId and session_id as payload of the POST request, i.e., as data in the request body. Then it should work.
This is not related to IBM Watson Assistant, but how http requests work.