SharePoint REST API endpoint filter

Kinasz, Mateus 60 Reputation points


I am using office365 library in python to get the number of views in a specific site.

from office365 import ClientContext, RequestOptions

ctx = ClientContext(site_url).with_client_certificate(**cert_credentials)

request = RequestOptions(f"{site_url}/_api/search/query?querytext={querytext}")

response = ctx.pending_request().execute_request_direct(request)

I can use the 2 queries below which give me some results.

The first one gives me all the paths containing '/sites/thehub'

And the second all the contentclass which is equal to 'STS_ListItem_WebPageLibrary'

querytext = "'Path:{site_url}/sites/thehub'&$selectproperties='Title,Description,HitHighlightedSummary,path,contentclass,ViewsLifeTime,ViewsLifeTimeUniqueUsers,ViewsRecent,ViewsLast1Day'&rowlimit=500""'contentclass:STS_ListItem_WebPageLibrary'&$selectproperties='Title,Description,HitHighlightedSummary,path,contentclass,ViewsLifeTime,ViewsLifeTimeUniqueUsers,ViewsRecent,ViewsLast1Day'&rowlimit=500"

querytext = "'contentclass:STS_ListItem_WebPageLibrary'&$selectproperties='Title,Description,HitHighlightedSummary,path,contentclass,ViewsLifeTime,ViewsLifeTimeUniqueUsers,ViewsRecent,ViewsLast1Day'&rowlimit=500"

However, I cannot combine the two. I tried using filter with different syntaxes, but I cannot make it work.

Additionally, the ViewsLifeTimeUniqueUsers and ViewsLast1Day columns do not appear in the output.

A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
8,614 questions
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 27,116 Reputation points Microsoft Vendor

    Hi @Kinasz, Mateus,

    I'm glad to hear you solve the problem ,if you have any issue about SharePoint, you are welcome to raise a ticket in this forum.

    By the way, since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others." and according to the scenario introduced here: Answering your own questions on Microsoft Q&A, I would make a brief summary of this thread:

    [SharePoint REST API endpoint filter]

    Issue Symptom:

    unable to combine the two querytext. Also tried using filter with different syntaxes, but still doesn't work.


    Fixed by using 'refinementfilters'. Could refer to following query


    You could click the "Accept Answer" button for this summary to close this thread, and this can make it easier for other community member's to see the useful information when reading this thread. Thanks for your understanding!

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Kinasz, Mateus 60 Reputation points

    I have the answer.

    You need to use 'refinementfilters'

    This is the query:

    0 comments No comments