Search documents in OneDrive, Sharepoint and teams separately

Mohannad Alahdab 1 Reputation point
2021-03-02T09:02:27.58+00:00

Can I use msgraph API to search documents programmatically in OneDrive, Sharepoint and teams separately since OneDrive and Teams documents are saved as SharePoint list and when I tried to search SharePoint I got OneDrive documents as well!

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,038 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Danstan Onyango 3,816 Reputation points Microsoft Employee
    2021-03-10T11:49:59.81+00:00

    MS Graph will provision a drive resource for each OneDrive SharePoint or SharePoint document libraries associated with teams.
    Using this, you can search each drive on its own using its id like by calling GET /drives/drive-id/root/search(q='search-text')

    You can get the users drive-id using GET /me/drives
    Or teams document library drive-id using GET /groups/{team-id}/drives
    Or just get GET /drives

    depending on your scenario and permissions.

    So the base line is if you are using the drive-id, you should be able to search each accessible drive on its own. Graph Search Files Docs details this further.

    0 comments No comments