WebSocket Authentication Fails but REST API Works with Same Token

Hi Team,

I’m working with the Upstox WebSocket API:
wss://api.upstox.com/v3/feed/market-data-feed/authorize?access_token=MyTOKEN

Even though the same access token works with the REST API (‘https://api.upstox.com/v2/option/chain?instrument_key=NSE_EQ|INE947Q01028&expiry_date=2025-05-29’), I get this error when using WebSocket:

javax.websocket.DeploymentException: Handshake error.
at org.glassfish.tyrus.client.ClientManager$3$1.run(ClientManager.java:658)
at org.glassfish.tyrus.client.ClientManager$3.run(ClientManager.java:696)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
at — Async.Stack.Trace — (captured by IntelliJ IDEA debugger)
at java.base/java.util.concurrent.FutureTask.(FutureTask.java:151)
at java.base/java.util.concurrent.AbstractExecutorService.newTaskFor(AbstractExecutorService.java:98)
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:122)
at org.glassfish.tyrus.client.ClientManager.connectToServer(ClientManager.java:493)
at org.glassfish.tyrus.client.ClientManager.connectToServer(ClientManager.java:299)
at com.scanner.stockapi.controller.UpstoxWebSocketClient.main(UpstoxWebSocketClient.java:76)
Caused by: org.glassfish.tyrus.client.auth.AuthenticationException: Authentication failed.

Things I’ve verified:

  • Added scope: read websocket_feed offline_access
  • Token works with REST
  • Using correct WebSocket URI with access_token= in the query string

Please advise on how to resolve this.

Thanks!

@Gaurav_48570628 You need to include the access token in the request headers. Try using the cURL command below—this will return an authorized WebSocket URL in the response, which you can use for a one-time connection.

curl -X 'GET' \
  'https://api.upstox.com/v3/feed/market-data-feed/authorize' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer {access_token}

Thanks