tmp dev
tmp dev

Reputation: 9183

Filtering Groups with Contains

I'm trying to write a Microsoft Graph query to search for groups containing a particular substring and does not seem to work. I am trying

https://graph.microsoft.com/v1.0/groups?$filter=contains(displayName, 'test')

I get an error

{
    "error": {
        "code": "Request_BadRequest",
        "message": "An unknown function with name 'contains' was found. This may also be a key lookup on a navigation property, which is not allowed.",
        "innerError": {
            "date": "2021-07-05T02:45:01",
            "request-id": "bbbc58ed-bc0f-4a76-ba41-42a467736518",
            "client-request-id": "fd41da80-0382-8431-027f-e76fd9054fc8"
        }
    }
}

According to this, contains is not supported, is there a different way to get this done, I would assume this is a standard requirement and there should be some way to get this done. My use case scenario is that a user types in a team name and I return all the teams which contains the given string. Is this possible through the search API?

Upvotes: 3

Views: 1368

Answers (1)

JayakrishnaGunnam-MT
JayakrishnaGunnam-MT

Reputation: 1866

Contains is not supported, we have two options to search or filter

Search Parameters: we can use search parameters , search only works on 'displayName' and 'description' fields, searching on 'directory objects' require a special request header: 'ConsistencyLevel: eventual'

Filter Parameters: We can use the filter query parameter to search the Group by Display Name. For example, we can search the groups whose display Name is start with 'Test',the request url like this: https://graph.microsoft.com/v1.0/groups?$filter=startswith(displayName,'Test')

Please check this Thread for reference , How to search the group by the DisplayName using Microsoft Graph.

Reference to Use query parameters to customize responses

Upvotes: 1

Related Questions