I'm trying to add a button on a document list which should cause a user stop following the document.

a REST Call from the URL


gave me this error XML

<m:error xmlns:m="..">
     -1, Microsoft.SharePoint.Client.ClientServiceException
    <m:message xml:lang="en-US">
      The HTTP method 'GET' cannot be used to access the resource 
     'StopFollowing'. The operation type of the resource is specified as 
     'Default'. Please use correct HTTP method to invoke the resource.

Debugger Info

And when I run my script

I get following "403 FORBIDDEN" in Debugger

And the Error Message is

security validation for this page is invalid and might be corrupted. Please 
use your web browser's Back button to try your operation again."}}}

I tried to execute as admin in and as User but both results are same so I'm wondering is there a way to implement REST on SP site because it is the recomended way from the dev.office. Or would be the Java object model more apropriate


To implement stop following a document using REST you will have to issue a POST request. A sample code is shared below :

use strict';  

var hostweburl;  
var appweburl;  
var documenturl;  
var followDocEndpoint;  

hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));  
appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"))  

followDocEndpoint = decodeURIComponent(appweburl) + "/_api/social.following";  

    documenturl = document.getElementById("stopFollow").value;  
$.getScript(hostweburl + "/_layouts/15/SP.RequestExecutor.js");  

function stopFollow()   
    url: followDocEndpoint + "/stopfollowing",  
    type: "POST",  
    data: JSON.stringify({  
        "actor": {  
                "type": "SP.Social.SocialActorInfo"  
            "ActorType": 1,  
            "ContentUri": documenturl,  
            "Id": null  
        "accept": "application/json;odata=verbose",  
        "content-type": "application/json;odata=verbose",  
        "X-RequestDigest": $("#__REQUESTDIGEST").val()  
    success: function()   
        alert('The user has stopped following the document.');  
    error: stopFollowErrorHandler  

function stopFollowErrorHandler(data, errorcode, errormessage)  
 alert("Couldn't stop following the document" + errormessage);  

function getQueryStringParameter(paramToRetrieve)  
var params = document.URL.split("?")[1].split("&");  
for (var i = 0; i < params.length; i = i + 1) {  
    var singleParam = params[i].split("=");  
    if (singleParam[0] == paramToRetrieve) return singleParam[1];  

Output : enter image description here

Stop Following Document using REST

  • My first atempts weren't succesful. Im trying to understand the getQueryStringParameter Function, because I get an Error message on the second split() Method regarding to my URL I do not have the char "&" in it what is problably causing my error. My URL looks like this: sp.egger.com/teams/corporate_communications/eggernet/… – Andreas Vitzthum Aug 3 '17 at 7:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.