Navigation

    SmartAPI Forum
    • Register
    • Login
    • Search
    • Categories
    • Popular
    • Groups
    • FAQs
    • API Docs

    websocketv2 throws 401 error on nodejs sdk

    Bugs
    0
    4
    29
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      bhxshxn last edited by

      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

      1 Reply Last reply Reply Quote 2
      • B
        BalaDhruv last edited by

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

        M D 2 Replies Last reply Reply Quote 1
        • M
          Moderator_2 @BalaDhruv last edited by

          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

          1 Reply Last reply Reply Quote 0
          • D
            DevPatel @BalaDhruv last edited by

            @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',
            });

            1 Reply Last reply Reply Quote 0
            • First post
              Last post