Forum Discussion

PapagenoSweden's avatar
PapagenoSweden
Copper Contributor
Feb 23, 2018

Cannot get modern team sites with REST

Hi, guys!

 

I use a REST call to retrieve all sites the current user is following, but modern team sites don't show. I get all classic sites and also modern communication sites, but not modern team sites.

Any idea why?


This is my call:

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


At this point I use the type 15 to get everything the user is following (according to the SocialActorTypes enumeration found https://msdn.microsoft.com/library/Microsoft.SharePoint.Client.Social.SocialActorTypes.aspx). I get people, documents, sites and tags, but still no modern team sites.

 

Any hint or info on this subject would be appreciated. Thanks.

 

4 Replies

  • Anonymous's avatar
    Anonymous

    Just tried your query but at my tenant it returns the modern teamsites.. so maybe it is a private teamsite?

    • PapagenoSweden's avatar
      PapagenoSweden
      Copper Contributor

      Hi, Paul, and thanks for your reply.

       

      If you're referring to the Privacy Settings dropdown in the Site Information pane, all my modern team sites are "Public". But no one is returned by my REST call. Are there any other settings needed?

       

      Funny thing is that when I go to the page https://[tenant]/_layouts/15/sharepoint.aspx, I find a "following" section in the left nav. In this section all the sites I'm following appear, regardless of they being classic, communication or what not. It is this behaviour I'm trying to mimic using my REST call. Without any luck, obviously. Any other suggestions?

      • PapagenoSweden's avatar
        PapagenoSweden
        Copper Contributor

        Apparently, this subject has been up for discussion before. I found this post which describes my problem in a nutshell. A modern team site uses GROUP as  web template and above mentioned post had a solution. Thanks.

         

        The solution in this case was to use a web service instead and call it with a good old XMLHttpRequest. Here's a sample if anyone else have the same issue.

         

          var xhr = new XMLHttpRequest();
          xhr.onreadystatechange = function(){
            var followedSites = [];
        
            if (xhr.readyState==4 && xhr.status==200) {
              var data = JSON.parse(xhr.responseText);
        
              for(var i=0;i<data.Items.length;++i){
                followedSites.push({
                  Acronym: data.Items[i].Acronym,
                  Title: data.Items[i].Title,
                  Url: data.Items[i].Url
                });
              }
              console.log(followedSites);
            }
          };
          xhr.open('GET', this.context.pageContext.web.absoluteUrl + '/_vti_bin/homeapi.ashx/sites/followed?mostRecentFirst=true&start=0&count=100&fillSiteData=true', true);
          xhr.send();

         

Resources