Search code examples
c#.net-coremicrosoft-graph-sdksgroup-membership

MS Graph SDK: How to add URL segment to filter for specific member type?


I'd like to get group members from Graph. No problem, the API is there. I now want to filter for members that are groups themselves and there even is a sample for this on the docs page:

enter image description here

See the /microsoft.graph.group part of the URL? That's what I want, but via Graph SDK.

Switching the sample to C# to see the corresponding code there is no evidence of this microsoft.graph.group URL part anymore:

enter image description here

Am I blind? How to apply this filter via Graph SDK?


Solution

  • Filtering is not supported by SDK code generator. As an alternative you can add segment to request url manually.

    var graphClient = new GraphServiceClient( authProvider );
    var requestUrl = graphClient.Groups["{group-id}"]
        .TransitiveMembers
        .AppendSegmentToRequestUrl("microsoft.graph.group?$count=true");
    
    var group = await new GroupTransitiveMembersCollectionWithReferencesRequest(requestUrl, graphClient, null)
        .Header("ConsistencyLevel", "eventual")
        .GetAsync();
    

    Graph issue