8

Sharepoint Online offers a view of the frequent sites of the current user. It is available in the home page of the "My Site" of the user. I'm asking if there is a REST API (or something like) to get the FREQUENT SITES of the user programmatically? Maybe also a Graph API query?

frequent sites

I know there is a way to get the LAST VISITED sites of the user but I don't mean that

/_api/search/query?querytext='contentclass:STS_Web'&sortlist='ViewsRecent:descending,ViewsLifeTime:descending'&selectproperties='Title,Author,Url'

And there is a way to get the FOLLOWED SITES but I don't mean neither that

/_api/social.following/my/followed(types=4)

Thank you

PS: I found the results in this call (sniffing the network calls of the page) but the host is strange...): https://northeurope1-sphomep.svc.ms/api/v1/sites/feed?acronyms=true&start=0&count=12

  • Maybe the Microsoft Graph API is able to do it. – Smile4ever Nov 29 '17 at 15:01
  • 1
    Your search query doesn't list what you viewed recent, but what anyone has viewed and you have access to. Having access to the beta insights API in the MS Graph via SP context would be useful indeed. – Mikael Svenson Dec 6 '17 at 13:59
  • Microsoft Graph People Insignts seems a good candidate but it offers just: 1 ) Trending documents 2) Used documents 3) Shared documents but not frequent documents. To be honest I'm not so obsessed by frequent documents but the One Drive for Business page is offering it. So is quite natural to ask for it. – Piero Dec 19 '17 at 8:12
  • 2 years with no answers at all – Piero Mar 18 at 9:37
  • Piero take a look to my answer, should work for you ( mark as solved if it does ) Thanks – Alberto S. May 11 at 12:14
1

Using the GRAPH API

  • OPTION 1 ( Best & simplest option )

You can query the graph endpoint:

https://graph.microsoft.com/v1.0/me/insights/used?$filter=ResourceVisualization/Type eq spsite'&$orderby=lastUsed/lastAccessedDateTime desc

It will return accurate information of the latest visited sites.

  • OPTION 2

The recently Visited Sites webpart from the sharepoint sp-starter-kit, already shows the latest visited sites by the current user with the help of graph api.

This webpart gets the latest web pages the user has visited, on the endpoint:

https://graph.microsoft.com/v1.0/me/insights/used?$filter=ResourceVisualization/containerType eq 'Site' and ResourceVisualization/Type eq 'Web'

Then, builds an array of unique site url based on the results returned by the query.

Please notice that option 2's results are always based on visited page items or files, then, if a user only visits the site homepage, such result wont be reflected in the query answer.

Using Sharepoint REST API

If you are looking for an alternative way of retrieving the latest visited sites, you can query the below endpoint ( replace top with number of desired results )

/_vti_bin/homeapi.ashx/sites/recent??mostRecentFirst=true&start=0&count=${top}&acronyms=true

And dont forget to add the additional header SPHome-ClientType. Here is a javascript example:

return await (await this.httpCli.get(
        `/_vti_bin/homeapi.ashx/sites/recent??mostRecentFirst=true&start=0&count=${top}&acronyms=true`,
        SPHttpClient.configurations.v1,
        { headers: { "SPHome-ClientType": "SharePointIOS" } })
      ).json();

PS1: feel free to test the microsoft graph api here

PS2: This sharepoint rest api will be exposed and documented some day in graph api, as described on this github thread.

| improve this answer | |

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.