Introduction
SharePoint Site has been enabled with a new type of social feature. You can now follow the site. If you started following the site, you will be up to date on the site updates. We can benefit from a lot of advantages, such as saving/copying/moving documents or items more easily, viewing recent items from the site, etc.
In this post, I’ll show you how to check whether the current user is following the SharePoint Site or not. The below REST API format will help to identify this;
https://domain.sharepoint.com/_vti_bin/homeapi.ashx/sites/followed/isFollowed?url=https://domain.sharepoint.com/sites/sitename
URL - This is the required parameter. You must pass this parameter to check the user is following the site associated with the URL. This enables us to run the code from any SharePoint site.
This returns the result in a Boolean value. If the current user follows the site, the result would be true. And the user doesn’t follow, it returns false.
To test this, navigate to any SharePoint Site. Then open the browser’s web console and paste the below code snippet:
-
-
- function getRequest(url) {
- var request = new XMLHttpRequest();
- return new Promise(function(resolve, reject) {
- request.onreadystatechange = function() {
- if (request.readyState !== 4) return;
- if (request.status >= 200 && request.status < 300) {
- resolve(request);
- } else {
- reject({
- status: request.status,
- statusText: request.statusText
- });
- }
- };
-
- request.open('GET', url, true);
- request.setRequestHeader("Content-Type", "application/json;charset=utf-8");
- request.setRequestHeader("ACCEPT", "application/json; odata.metadata=minimal");
- request.setRequestHeader("ODATA-VERSION", "4.0");
- request.send();
-
- });
- }
-
- function isFollow(url){
- getRequest(location.origin+"/_vti_bin/homeapi.ashx/sites/followed/isFollowed?url="+url).then(function(output){console.log(output.response); });
- }
-
- isFollow("https://contoso.sharepoint.com/sites/demo");
-