DEV Community

Sven Glöckner
Sven Glöckner

Posted on

2 1

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();
Enter fullscreen mode Exit fullscreen mode

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.

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (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

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more