1

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 searchString is a simple value like "my-search-term", the call succeeds.
  • If searchString is 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:

  1. ConsistencyLevel header: as this was listed in a different resource on the documentation.
  2. Manual HttpClient call: to rule out an SDK issue, I built and sent the request manually using HttpClient. The raw URL was https://graph.microsoft.com/v1.0/me/messages?$search="from:[email protected]". I received the exact same syntax error.
  3. 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.0
  • Microsoft.Identity.Web.GraphServiceClient: 3.14.1
5
  • Try to use the filter instead of search see, stackoverflow.com/questions/55359070/… Commented Sep 16 at 14:12
  • Sorry, I should have mentioned that I tried this as well. When I use the filter property, I get the same exception with a slightly different message: Invalid filter clause: Syntax error at position 5 in 'from:[email protected]'. Commented Sep 16 at 14:24
  • I tested your query in Graph Explorer and it works as expected. It is hard to tell without seeing a network trace, but it smells a bit like an encoding issue. Commented Sep 16 at 15:39
  • Could you add two additional items: 1) the HTTP request that was sent over the network (fiddler is a good option for this) and 2) the code for your custom HttpClient send method. Commented Sep 16 at 15:41
  • Thank you for the suggestions. In using fiddler to inspect the request, I noticed the double quotes had gotten removed from around the whole search value. I've been through so many variations, that I got a bit lost. Adding this back seems to have fixed the errors. Commented Sep 16 at 16:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.