7

I'm trying to filter users by attributes in Microsoft Graph API. Essentially trying to get a list of users that have a given jobTitle assigned.

For example, https://graph.microsoft.com/v1.0/users?$filter=jobtitle eq 'ACCOUNT EXECUTIVE' returns a list of users.

My requirement is to query for users that do not have a JobTitle.

Tried https://graph.microsoft.com/v1.0/users?$filter=jobtitle ne null and got the following message.

{
    "error": {
        "code": "Request_UnsupportedQuery",
        "message": "Unsupported property filter clause operator 'NotEqualsMatch'.",
        "innerError": {
            "request-id": "c9b290bf-2902-4b79-b35b-0f5d251ad80b",
            "date": "2017-09-14T11:18:52"
        }
    }
}

3 Answers 3

7

$filter=department ge '!' appears to be a workaround here.

Sign up to request clarification or add additional context in comments.

2 Comments

Why does this work? This did exactly what I needed it to do. What's the significance with the '!'?
$filter=department ge ' ' (with a space) might be even better. The query works because the '!' is the second printable character in the ASCII table (the space is the first, that why I say it could be even better) asciitable.com Brilliant idea Leon!
2

According to this Git Issue, I don't think it's supported: https://github.com/microsoftgraph/microsoft-graph-docs/issues/239 (it eventually just revolves around finding rooms)

There is no way to filter the users collection for entities with surname equal to null or empty string. The value of the filter must be between 1 and 64 characters as documented here: https://msdn.microsoft.com/en-us/Library/Azure/Ad/Graph/api/entity-and-complex-type-reference#userentity - marych Apr 26, 2016

The lack of null filtering is due to the way users are indexed. We can't efficiently retrieve users with an indexed property unset. There are no plans to change that. - marych May 13, 2016

Comments

1

To resolve the issue, you can include the ConsistencyLevel: eventual attribute in the header of your request. This attribute ensures that your query is executed with eventual consistency, which can be particularly helpful in cases where the data might not be immediately consistent across all replicas.

In .NET, you can achieve this by creating an HttpRequestMessage object and adding the ConsistencyLevel header before sending the request. Here's an example:

HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
request.Headers.Add("ConsistencyLevel", "eventual");

By including this header attribute, you can potentially mitigate errors related to unsupported filter operators, as it ensures a consistent behavior in retrieving data from the Microsoft Graph API.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.