Question

Here's my api call to get news pages published on 2 sites in the last 60 days:

/_api/search/query?querytext='IsDocument:True AND FileExtension:aspx AND PromotedState:2 Path:https://xxx.sharepoint.com/sites/xxx Path:https://xxx.sharepoint.com/sites/xxx FirstPublishedDate>{Today-60}'

This works correctly in the results sources query builder, but when tested in Postman the date restriction is ignored.

Also curious about how to add a rowlimit to the api call to only return the latest say 5 results.

Was it helpful?

Solution

You could append &sortlist='FirstPublishedDate:descending'&startRow=0&rowlimit=5 to your request to sort response results and get the top five items.

You could know more about sharepoint search api here:

https://docs.microsoft.com/en-us/sharepoint/dev/general-development/sharepoint-search-rest-api-overview

OTHER TIPS

This seems to work:

 /_api/search/query?querytext='IsDocument:True AND FileExtension:aspx AND PromotedState:2  Path:https://xxxx.sharepoint.com/sites/xxx Path:https://xxx.sharepoint.com/sites/xxxx'&sortlist='FirstPublishedDate:descending'&startRow=0&rowlimit=5

Msft should provide a few more examples illustrating how to concatenate various components.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top