I'm working on a Graph API query where I am trying to get Groups based on certain conditions. Here is the query below
with 'ConsistencyLevel': 'eventual' header
https://graph.microsoft.com/v1.0/users?$count=true&$filter=startswith(displayName , 'xyz') and NOT(groupTypes/any(c:c+eq+'Unified')) and securityEnabled eq false and mailEnabled eq true&$select=displayName,mail
Property 'groupTypes' does not exist as a declared property or extension property.
How would I combine STARTS WITH and NOT operator and pass it in $filter?
Note that: To query groups based on certain conditions, you need to make use of 'groups' endpoint instead of 'users'.
When I executed the same query as you, got the same error:
GET https://graph.microsoft.com/v1.0/users?$count=true&$filter=startswith(displayName , 'test') and NOT(groupTypes/any(c:c+eq+'Unified')) and securityEnabled eq false and mailEnabled eq true&$select=displayName,mail
ConsistencyLevel: Eventual
Hence, to resolve the error make use of groups endpoint:
GET https://graph.microsoft.com/v1.0/groups?$count=true&$filter=startswith(displayName, 'test') and not groupTypes/any(c:c eq 'Unified') and securityEnabled eq false and mailEnabled eq true&$select=displayName,mail
ConsistencyLevel: Eventual
Output:
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups(displayName,mail)",
"@odata.count": 1,
"value": [
{
"displayName": "Testgroup",
"mail": "samplegroup@xxx.onmicrosoft.com"
}
]
}