I'm using the Microsoft.Graph SDK (v5.92.0) in an ASP.NET Core 9 application to search a user's messages.
A simple search with a single term works correctly, but when I use a KQL-formatted string as specified in the official documentation, the request fails.
Here is the GraphServiceClient call I am making:
var searchString = "\"from:[email protected]\""; // Example failing search value
var graphMessages = await _graphServiceClient.Me.Messages
.GetAsync(requestConfiguration =>
{
requestConfiguration.QueryParameters.Select = [ "id", "receivedDateTime", "subject", "from", "bodyPreview", "webLink" ];
requestConfiguration.QueryParameters.Top = 5;
requestConfiguration.QueryParameters.Search = searchString;
});
The problem:
- If
searchStringis a simple value like"my-search-term", the call succeeds. - If
searchStringis a KQL value like"from:[email protected]", the call fails.
It throws a Microsoft.Graph.Models.ODataErrors.ODataError exception with the message:
Syntax error: character ':' is not valid at position 4 in 'from:[email protected]'.
What I've already tried:
ConsistencyLevelheader: as this was listed in a different resource on the documentation.- Manual
HttpClientcall: to rule out an SDK issue, I built and sent the request manually usingHttpClient. The raw URL washttps://graph.microsoft.com/v1.0/me/messages?$search="from:[email protected]". I received the exact same syntax error. - Search variations: I have tried various quoting combinations (e.g., with and without the outer double quotes, parenthesis mixing of properties, etc.), all of which led to the same or similar errors.
Packages in use:
Microsoft.Graph: 5.92.0Microsoft.Identity.Web.GraphServiceClient: 3.14.1