Skip to content

Latest commit

 

History

History
148 lines (111 loc) · 5.28 KB

File metadata and controls

148 lines (111 loc) · 5.28 KB
author learafa
title Get websocket endpoint
description Use of these APIs in production applications is not supported.
ms.localizationpriority medium
ms.subservice sharepoint
doc_type apiPageType
ms.date 04/05/2024

Get websocket endpoint

Namespace: microsoft.graph

[!INCLUDE beta-disclaimer] Use of these APIs in production applications is not supported.

Allows you to receive near-real-time change notifications for a drive and list using socket.io. Socket.io is a popular notifications library for JavaScript that utilizes WebSockets. To learn more, see socket.io.

Permissions

Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.

[!INCLUDE permissions-table]

HTTP request

GET /me/drive/root/subscriptions/socketIo
GET /drives/{driveId}/root/subscriptions/socketIo
GET /drives/{driveId}/list/subscriptions/socketIo
GET /groups/{groupId}/drive/root/subscriptions/socketIo
GET /sites/{siteId}/lists/{listId}/drive/root/subscriptions/socketIo

Example

Request

GET /me/drive/root/subscriptions/socketIo

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]

[!INCLUDE sample-code] [!INCLUDE sdk-documentation]


Response

If successful, this method returns a 200 OK response code and a subscription object in the response body.

HTTP/1.1 200 OK
Content-type: application/json

{
  "id": "opaqueId-fj3hd7yf283jfk193726nvc2w3i2diemdu8",
  "notificationUrl": "https://f3hb0mpua.svc.ms/zbaehwg/callback?snthgk=1ff3-2345672zz831837523"
}

The notificationUrl returned is a socket.io endpoint URL. To use it with a socket.io client, split the string on the /callback? token. The part of the string before /callback? is the socket.io endpoint URL and the part of the string after is an opaque query string that must be given to the libary.

The following example shows how to use the notificationUrl with socket.io in JavaScript.

<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.8.1/socket.io.js"></script>
<script>
  // This is the notificationUrl returned from this API
  var notificationUrl = "https://f3hb0mpua.svc.ms/zbaehwg/callback?snthgk=1ff3-2345672zz831837523";
  
  // 'io' comes from the socket.io client library
  var socket = io(notificationUrl, {
    transports: ['websocket'] // Make sure to use "websocket" instead of the default value of "polling" which isn't supported
  });
  
  socket.on("connect", () => {
    console.log(`connect`, socket.id);
  });
  
  socket.on("disconnect", () => {
    // Returns "undefined" on disconnect
    console.log(`disconnect`, socket.id);
  });
  
  socket.on("notification", (data) => {
    console.log(`Notification received:`, data);
  });
</script>