SP Online search REST api calls return different results than the query builder
-
13-02-2021 - |
Вопрос
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.
Решение
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:
Другие советы
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.
Не связан с sharepoint.stackexchange