Search code examples
c#microsoft-graph-apionedrive

Microsoft Graph: Search for DriveItems on a SharePoint drive returns no results


I have files in a SharePoint Drive and want to develop a full-text search. The following call in the Graph Explorer works, finding my files either by filename or content:

https://graph.microsoft.com/v1.0/drives/{my drive id}/root/search(q='my search word')

The same call from my Azure hosted ASP.NET app using the Microsoft.Graph-NuGet package allways returns an empty list:

await _client
  .Drives[{my drive id}]
  .Root
  .Search({my search word})
  .Request()
  .GetAsync()

_client is an authenticated GraphServiceClient. For authentication, I receive a token through the Azure AD endpoint (app registered in the Azure Portal), not from the v2 Endpoint (app registered in the Application Registration Portal). To exclude this as a reason, I used the v2 Endpoint but there was no difference.

The application has the Files.ReadWrite.All permission scope. Receiving, saving and deleting files works fine. Only searching fails.

As a test, I gave my application all rights Graph Explorer has with no difference. I compared the URL the GraphServiceClient prepared but everything looked fine.


Solution

  • This question described the same problem two days later. In a comment the author stated, it started working yesterday without him changing anything. I tested it today with my same old Code. What can I say? It works now! Looks like it was a bug on Microsofts side?