Reputation: 27
Currently, we are looping through each siteid
in a tenant to search for a given keyword using:
/v1.0/sites/{siteid}/drive/search(q='{search-query}')
In our case, we have more than 500 sites under our tenant so for searching using this API we have to pass each siteid
and process the results.
Is there a way out of this? Can we search for keywords across the whole tenant with a single API call?
Upvotes: 1
Views: 196
Reputation: 33094
Currently no, Microsoft Graph doesn't support searching across site
resources like this.
For the authenticated user, you can scope the search to include any items that can access via /me/drive/search(q='{search-query}')
. This is a little different than what you're doing by iterating through sites
so I suspect this won't give you the expected results (although you certainly can, and should, confirm that for yourself).
What you're more likely looking for is the SharePoint Search REST API. You can use this API by issuing an GET
to a URI that looks something like this:
https://{tenant}.sharepoint.com/_api/search/query?querytext='sharepoint'
In order to use this API will need an access_token
for SharePoint however.
If you're using the v1 Endpoint this should be pretty straightforward. You'll need to update your App registration to include the SharePoint API but once that is done you can simply refresh your existing access_token
while switching your resource
to https://{tenant}.sharepoint.com/
. This will give you a new token with permission to call the SharePoint API.
Unfortunately, this won't work with the v2 Endpoint as the SharePoint REST API does not support these tokens today. You would, therefore, need to switch to v1 and force your user to reauthenticate which may be a bit more challenging.
Upvotes: 1