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.

Speedy emails, satisfied customers

Postmark Image

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay