WebSocket connection to notification URL fails

Mikkel Munck Rasmussen 0 Reputation points
2024-09-19T06:59:28.15+00:00

I am following this guide on how to get a Websocket endpoint for my onedrive https://learn.microsoft.com/en-us/graph/api/subscriptions-socketio?view=graph-rest-1.0&tabs=http

I get a fine notification Url back from /subscribtions/socketIo endpoint that looks something like this:

'wss://westeurope0-0.pushnp.svc.ms/notifications?token=TOKEN&applicationId=APP_ID'

(Removed token and appId in this post)

But the when I instantiate a new Websocket with the notification Url it fails with the error message:

'WebSocket connection to (NOTIFICATION_URL) failed: Connection closed before receiving a handshake response'

This the code I use:

 const response = await fetch(
   `${OneDriveConnection.graphUrl}/drive/root/subscriptions/socketIo`,
   {
   	headers: {
    	Authorization: "Bearer " + MY_ACCESS_TOKEN,
		},
    },
 );
 const data = await response.json();
 const wsConnection = new WebSocket(data.notificationUrl);

What could be the issue here?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,113 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.