How to search across mulitple sharepoint sites using microsoft graph search api ?

harryK9 11 Reputation points
2022-06-30T10:02:03.58+00:00

Hi,
I need to search across multiple sharepoint sites using microsoft graph search api.
Right now using the below API, I am able to get resources in one site only.

URL - https://graph.microsoft.com/v1.0/sites/{site-id}/drive/root/search(q='account')  
  
Header -  
Authorization : Bearer {AccessToken}  
  

Above api only works for the mentioned {siteId}, instead I want results from multiple sites.

Reference: https://learn.microsoft.com/en-us/graph/api/driveitem-search?view=graph-rest-1.0&tabs=http

Is there any way to achieve this?
Any help would be appreciated!

Thanks

Microsoft 365 and Office SharePoint For business Windows
Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. HarmeetSingh7172 4,826 Reputation points
    2022-06-30T10:47:20.823+00:00

    Hi @harryK9

    Hope you are doing well.

    You can use Microsoft Search API to search across multiple SharePoint Sites.

    However, if you are looking for a way to limit your search to few mentioned sites, then you can refer this below sample request.

     POST /search/query  
          
      {  
          "requests": [  
              {  
                  "entityTypes": [  
                      "driveItem"  
                  ],  
                  "query": {  
                      "queryString": "sample AND (Path:https://contoso.sharepoint.com/sites/sitename1 OR Path:https://contoso.sharepoint.com/sites/sitename2 OR Path:https://contoso.sharepoint.com/sites/sitename3)"  
                  }  
              }  
          ]  
      }  
    

    You can also refer to this answer posted by me.

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.


  2. Tong Zhang_MSFT 9,251 Reputation points
    2022-07-04T05:34:12.06+00:00

    Hi @harryK9 ,

    I agree with HarmeetSinghMSFT-7172's answer, you can use POST /search/query to search across multiple SharePoint sites. Please refer to this article:https://learn.microsoft.com/en-us/graph/search-concept-files

    In addition, as far as I know, currently there is no other method can achieve this.

    Thanks for your understanding.


    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.



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.