websocketv2 throws 401 error on nodejs sdk


  • websocketv2 throws 401 error on nodejs sdk where as it works on the python sdk with same credentials please fix this this the error:
    Error: Unexpected server response: 401
    at ws.onerror (/home/bhushan/workspace/botlab-v-2/streamer/node_modules/smartapi-javascript/lib/websocket2.0.js:89:15)
    at callListener (/home/bhushan/workspace/botlab-v-2/streamer/node_modules/smartapi-javascript/node_modules/ws/lib/event-target.js:290:14)
    at WebSocket.onError (/home/bhushan/workspace/botlab-v-2/streamer/node_modules/smartapi-javascript/node_modules/ws/lib/event-target.js:230:9)
    at WebSocket.emit (node:events:518:28)
    at emitErrorAndClose (/home/bhushan/workspace/botlab-v-2/streamer/node_modules/smartapi-javascript/node_modules/ws/lib/websocket.js:1033:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

    Node.js v20.11.0


  • @BalaDhruv This error occurs when you pass invalid parameter in below function. check it first.

    const web_socket = new WebSocketV2({
    jwttoken: 'YOUR_JWT_TOKEN_HERE',
    apikey: 'YOUR_API_KEY_HERE',
    clientcode: 'YOUR_CLIENT_ID_HERE',
    feedtype: 'YOUR_FEED_TOKEN_HERE',
    });


  • Hi @BalaDhruv

    On websocket, we throw 401 error occurs when auth token is empty or incorrect. Kindly verify if the authorization token fetched from the login API is not expired.
    Kindly let us know if the issue still occurs with valid token.

    Regards,
    SmartAPI team


  • I am also getting the same issue. how can i solve this?