Is it possible to filter users by group (memberOf) when using API endpoint /users to get a list of users?

Franziska Blume 20 Reputation points
2023-06-15T11:58:50.3433333+00:00

e.g. https://graph.microsoft.com/v1.0/users?$filter=memberOf/any(c:startswith(c/displayName,+'GROUPNAME')) does not work and we get an error:

{
    "error": {
        "code": "Request_UnsupportedQuery",
        "message": "Unsupported or invalid query filter clause specified for property 'memberOf' of resource 'User'.",
        "innerError": {
            "date": "2023-06-15T11:51:25",
            "request-id": "8fc5b8bd-7e3f-4deb-9054-b7d88110febb",
            "client-request-id": "e54c1f88-9325-a98b-7fc0-6707ef9f2b31"
        }
    }
}

But we need the filter to limit the amount of users which should be returned. Is there any possibility to do this (and if yes, what is the right syntax for the query parameter 'filter')?

Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. TH-4749-MSFT 3,315 Reputation points
    2023-06-15T14:00:43.4533333+00:00

    Hello Franziska Blume,

    Thanks for reaching out. The /users query does not return the membersOf property by default and you have to use the expand parameter for example /users$expand=memberOf query to return group membership of users. Unfortunately, the $expand parameter does not support advanced filtering as mentioned in the documentation. Hence you cannot filter further using the $filter parameter along with the $expand parameter.

    253620-image.png


    I would suggest voicing your query and feedback on the Graph Feedback Forum.

    You can however run the below query on a user account:

    https://graph.microsoft.com/beta/users/[UserId]/memberOf?$filter=startsWith(displayName,'[GroupName]')&$count=true

    Please ensure you add the ConistencyLevel to 'eventual' in the header before running the query.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Thanks.

    0 comments No comments

  2. TH-4749-MSFT 3,315 Reputation points
    2023-06-19T14:29:37.4033333+00:00

    Hello Franziska Blume,

    Good Day. Hope all is well.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Thanks.

    0 comments No comments

  3. TH-4749-MSFT 3,315 Reputation points
    2023-06-21T14:03:29.7866667+00:00

    Hello Franziska Blume,

    Good Day. Hope all is well.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Thanks.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.