SOLVED

How do I search across all sites using Microsoft Graph?

%3CLINGO-SUB%20id%3D%22lingo-sub-353060%22%20slang%3D%22en-US%22%3EHow%20do%20I%20search%20across%20all%20sites%20using%20Microsoft%20Graph%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-353060%22%20slang%3D%22en-US%22%3E%3CP%3EI%20want%20to%20develop%20an%20application%20that%20displays%20a%20search%20result.%20For%20testing%20I%20uploaded%20a%20couple%20of%20files%20to%20the%20default%20document%20library%20in%20the%20root%20site.%20I%20can%20see%20these%20files%20with%20the%20following%20request%3A%3C%2FP%3E%3CPRE%3Ehttps%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2Fsites%2Froot%2Fdrive%2Froot%2Fsearch(q%3D'Test')%3C%2FPRE%3E%3CP%3E%3CSPAN%3EHowever%2C%20one%20of%20the%20requirements%20is%20that%20the%20query%20should%20match%20files%20regardless%20of%20in%20which%20site%20they%20are%20stored.%20As%20I%20understand%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fgraph%2Fapi%2Fdriveitem-search%3Fview%3Dgraph-rest-1.0%23searching-for-items-a-user-can-access%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ethe%20documentation%3C%2FA%3E%3CSPAN%3E%26nbsp%3BI%20should%20use%20something%20like%20this%3A%3C%2FSPAN%3E%3C%2FP%3E%3CPRE%3E%3CSPAN%20class%3D%22pln%22%3Ehttps%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3A%3C%2FSPAN%3E%3CSPAN%20class%3D%22com%22%3E%2F%2Fgraph.microsoft.com%2Fv1.0%2Fme%2Fdrive%2Fsearch(q%3D'Test')%3C%2FSPAN%3E%3C%2FPRE%3E%3CP%3EThe%20query%20is%20the%20same%20as%20in%20the%20first%20example%20but%20the%20results%20are%20empty.%3C%2FP%3E%3CPRE%3E%3CSPAN%20class%3D%22pun%22%3E%7B%3C%2FSPAN%3E%0A%20%20%20%20%3CSPAN%20class%3D%22str%22%3E%22%40odata.context%22%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3A%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22str%22%3E%22https%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2F%24metadata%23Collection(driveItem)%22%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%2C%3C%2FSPAN%3E%0A%20%20%20%20%3CSPAN%20class%3D%22str%22%3E%22value%22%3C%2FSPAN%3E%3CSPAN%20class%3D%22pun%22%3E%3A%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22pun%22%3E%5B%5D%3C%2FSPAN%3E%0A%3CSPAN%20class%3D%22pun%22%3E%7D%3C%2FSPAN%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-353249%22%20slang%3D%22en-US%22%3ERe%3A%20How%20do%20I%20search%20across%20all%20sites%20using%20Microsoft%20Graph%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-353249%22%20slang%3D%22en-US%22%3E%3CP%3EIt%20sounds%20to%20me%20like%20what%20you're%20looking%20for%20isn't%20the%20Graph%20API%2C%20but%20the%20Search%20API.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fdev%2Fgeneral-development%2Fsharepoint-search-rest-api-overview%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fdev%2Fgeneral-development%2Fsharepoint-search-rest-api-overview%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Contributor

I want to develop an application that displays a search result. For testing I uploaded a couple of files to the default document library in the root site. I can see these files with the following request:

https://graph.microsoft.com/v1.0/sites/root/drive/root/search(q='Test')

However, one of the requirements is that the query should match files regardless of in which site they are stored. As I understand the documentation I should use something like this:

https://graph.microsoft.com/v1.0/me/drive/search(q='Test')

The query is the same as in the first example but the results are empty.

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)",
    "value": []
}
1 Reply
Highlighted
Solution

It sounds to me like what you're looking for isn't the Graph API, but the Search API.

 

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