I want to show a list on our homepage of the most popular pages in our site collection. Is there a way of accessing this information using REST?
1 Answer
Use the ViewsLifetime and ViewsRecent metadata returned from http://site/subsite/_api/search/query (such as http://site/subsite/_api/search/query?querytext='ContentTypeId:0x010100C568*'). No views is a null value.
(in JSON the return looks like)
20: {
__metadata: {
type: "SP.KeyValue"
}-
Key: "ViewsLifeTime"
Value: "246"
ValueType: "Edm.Int64"
}-
21: {
__metadata: {
type: "SP.KeyValue"
}-
Key: "ViewsRecent"
Value: "98"
ValueType: "Edm.Int64"
}
-
-
That's just the default starting prefix for a page content type. Its just as an example of the search functionality. You can get a the content type ID's from Powershell, SP Designer or by going to Site Settings > Content Types and looking at the shortcuts. You could search by most any tag available in the metadata (name, title, author, etc). Microsoft has their API syntax reference <a href="msdn.microsoft.com/en-us/library/office/…>– GrahamCommented Apr 8, 2015 at 21:09