SharePoint REST: Search all files

davidelsner 66 Reputation points
2022-06-23T10:15:26.863+00:00

If I am using the SharePoint REST Api I usually send queries to the following endpoint:

https://myOrg.sharepoint.com/_api/search/postquery

If I am calling this endpoint in the name of a user, I receive all files from all site collections that this user is allowed to access.
This works fine except one thing that annoys me.
It seems that the user needs at least reading access to my root SharePoint site collection (https://myOrg.sharepoint.com)

But this does not really make sense to me. We do not store ANY files in the root site collection and I need to give users access there just to search files that are coming from other places anyway?
Why is this necessary? Is there another option how to search the files of all site collections?

I could now do a search against another site:

https://myOrg.sharepoint.com/sites/ampacet/_api/search/postquery

This results in exactly the same and files are returned that are not part of the "ampacet" site.

How can I:

  • Search all site collections without the involvement of a concrete site collection?
  • How can I search the files in only a single site collection?
Microsoft 365 and Office | SharePoint | Development
{count} votes

Accepted answer
  1. Tong Zhang_MSFT 9,251 Reputation points
    2022-06-27T09:26:36.017+00:00

    Hi @davidelsner ,

    According to my research and testing, the search service returns results from the entire site collection, so https://xxx.sharepoint.com/_api/search/postquery and https://xxxx.sharepoint.com/sites/xxxx/_api/search/postquery will return the same result.

    For reference:
    https://learn.microsoft.com/en-us/sharepoint/dev/general-development/using-the-sharepoint-search-query-apis#query-using-the-rest-service

    Unfortunately, it is currently not possible to search files in a specify site collection. I recommend you can mention a feedback on this issue . Many features of our current products are designed and upgraded based on customers’ feedback. With requirements like this increase, the problem may well be released in the future. Thanks for your understanding.

    Feedback:
    https://feedbackportal.microsoft.com/feedback/


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.