0

I'm working with TypeScript and SharePoint Framework in SharePoint Online.

I know that I can see all documents I follow by typing the following url in my browser:

https://[my-tenant]/_api/social.following/my/followed(types=2)

My question is : Is it possible to stop following a particular document using the same approach?

I tried this in my browser:

https://[my-tenant]/_api/social.following/stopfollowing(ActorType=1,ContentUri=@v,Id=null)?
@v='[my-tenant]:443/Shared%20Documents/test.docx'

But this gives me HTTP 400 (Bad request).

What I really would like to do is to create a function to stop following a document like this:

protected StopFollowingDocument(contentUri: string) {
    let rootUrl: string = this.context.pageContext.site.absoluteUrl;
    let restcall: string = rootUrl + "/_api/social.following/stopfollowing(ActorType=1,ContentUri=@v,Id=null)?@v='" + contentUri + "'";
    this.context.spHttpClient.get(restcall, SPHttpClient.configurations.v1);
}

But nothing happens when I try the above function.There is no error message and the document is still remains followed.

1 Answer 1

1

When you want to unfollow a document, you need to make a POST request. Currently in your code, you are making a GET request.

Modify your code as below in the webpart:

protected StopFollowingDocument(contentUri: string) {
    let rootUrl: string = this.context.pageContext.site.absoluteUrl;    
    let restcall: string = rootUrl + "/_api/social.following/stopfollowing(ActorType=1,ContentUri=@v,Id=null)?@v='" + contentUri + "'";
    this.context.spHttpClient.post(restcall, SPHttpClient.configurations.v1, null).then((response: SPHttpClientResponse) => {
      console.log("success unfollowing a document");          
    });
  }

Reference - Following people and content - REST API

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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