DEV Community

Sven Glöckner
Sven Glöckner

Posted on

Microsoft Graph API access denied in search for driveItems

Currently, I'm developing a Blazor Web App that reads files from another tenant's OneDrive. We need to have a search functionality through the files using the search for files capability.

I'm using MS Graph SDK.
The code boils down to a simple one-liner:

_graphClient.Users[userId].Drive.Search(term).Request().GetAsync();

However, it didn't work and throwed a 401 error:

Status Code: Forbidden
Microsoft.Graph.ServiceException: Code: accessDenied
Message: The caller does not have permission to perform the action.

I already registered my App and added the Files.Read.All permission but it just didn't work.
Now I remembered, that OneDrive for Business uses Sharepoint as backend and it organizes files within sites.
So they key is to also add the Sites.Read.All permission.

Discussion (1)

Collapse
nmoreau profile image
Nicolas Moreau (Microsoft)

Hi
The reason you are getting this is because the API does not support App Level permission.
See : github.com/microsoftgraph/microsof...
Nicolas