Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Client bug]: $search and $expand not working when mixed up together #2175

Closed
zagoskin opened this issue Oct 20, 2023 · 3 comments
Closed

[Client bug]: $search and $expand not working when mixed up together #2175

zagoskin opened this issue Oct 20, 2023 · 3 comments

Comments

@zagoskin
Copy link

zagoskin commented Oct 20, 2023

Describe the bug
As per microsoft documentation following this link, I am able to make queries about users for my tenant. When using the $search parameter, we are specified to use the ConsistencyLevel=eventual header for it to work (and adviced to use $count=true for some cases). This works as expected when making an HTTP request against the API. However, if I use the $expand parameter to get the users manager, I get an error "Request with $search query parameter only works through MSGraph with a special request header: 'ConsistencyLevel: eventual'", but this is not the case at all.

For example, the next request works just fine. I get the expected HTTP 200 result

GET https://graph.microsoft.com/v1.0/users?$filter=userType eq 'guest'&$search="displayName:jua"
ConsistencyLevel: eventual

Whereas the next one does not work

GET https://graph.microsoft.com/v1.0/users?$select=id,displayName,manager&$filter=userType eq 'guest'&$search="displayName:jua"&$expand=manager&$count=true  
ConsistencyLevel: eventual

I get an HTTP 400 response

{
    "error": {
        "code": "Request_UnsupportedQuery",
        "message": "Request with $search query parameter only works through MSGraph with a special request header: 'ConsistencyLevel: eventual'",
        "innerError": {
            "date": "2023-10-20T20:39:09",
            "request-id": "b39648ff-4c5b-4543-8059-845688f86b1d",
            "client-request-id": "1466b344-12f4-cf07-be3c-2a2b99ed5917"
        }
    }
}

Nonetheless, this does not work using the Microsoft.Graph package for .NET (version 5.31.0) even, which is actually where I found the bug and is my biggest concern. I am using .NET 7.

To Reproduce
Steps to reproduce the behavior in .NET application:

  1. Create a simple .Net 7 console application.
  2. Instantiate a GraphServiceClient
  3. Make the following call
var graphServiceClient = SomeFactory.CreateClient();
var userCollectionResponse = await graphServiceClient.Users.GetAsync(requestConfiguration =>
        {
            requestConfiguration.Headers.Add("ConsistencyLevel", "eventual");            
            requestConfiguration.QueryParameters.Filter = "userType eq 'member'";
            requestConfiguration.QueryParameters.Search = "\"displayName:whatever\"";
            requestConfiguration.QueryParameters.Top = 100;
            requestConfiguration.QueryParameters.Count = true;
            requestConfiguration.QueryParameters.Select = new string[] { "id", "displayName", "manager" };
            requestConfiguration.QueryParameters.Expand = new string[] { "manager" };
        }, cancellationToken: token);
  1. This throws an exception of type ODataError
Microsoft.Graph.Models.ODataErrors.ODataError: Request with $search query parameter only works through MSGraph with a special
request header: 'ConsistencyLevel: eventual'

Expected behavior
I can make a call to microsoft graph either using an HTTP request or the .NET package to retrieve specific users, using a $search query parameter in combination with the $expand parameter to also get their manager.

Package Version
5.31.0.

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser: microsoft edge
  • Version: 118.0.2088.57
@andrueastman
Copy link
Member

Thanks for raising this @zagoskin

The code snippet constructed looks correct. However, it seems due to a current API limitation, it is currently not possible to use the $expand parameter combined with the advanced queries on Microsoft Entra ID objects. You can find more information in the documentation below. Removing the $expand should result in a successful response.

https://learn.microsoft.com/en-us/graph/aad-advanced-queries?view=graph-rest-1.0&tabs=http#query-scenarios-that-require-advanced-query-capabilities

@zagoskin
Copy link
Author

zagoskin commented Oct 23, 2023

Thanks for the reply @andrueastman

I hope in the future we get access to combine these parameters then! Removing the $expand does work, so I guess I'll have to make a second call to get the manager field for every user and make a join-like operation. I would be great if the error we get was more in the lines of "query not supported" instead of pointing to a missing header.

@andrueastman
Copy link
Member

Thanks for confirming this @zagoskin

We'll close this for now as there is nothing SDK related to resolve. Incase of any API related questions/issues, you can always create a question at the link below.

https://learn.microsoft.com/en-us/answers/tags/161/ms-graph

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants