Search code examples
c#azuremicrosoft-graph-api

Microsoft Graph API get a list of Users by ids


I need to call Microsoft Graph API to get a list of users by a list of user id's.

And in the response, each User should include her Groups' id.

Anyone knows how to do this in C#?


Solution

  • One option is to expand memberOf and use casting for group. In Filter, use in operator and specify at most 15 users ids. 15 is the limit.

    var graphClient = new GraphServiceClient(requestAdapter);
    
    var result = await graphClient.Users.GetAsync((requestConfiguration) =>
    {
        requestConfiguration.QueryParameters.Expand = new string []{ "memberOf/microsoft.graph.group($select=id)" };
        requestConfiguration.QueryParameters.Filter = "id in ('{user-id1}','{user-id2}','{user-id3}','{user-id4}','{user-id5}','{user-id6}','{user-id7}','{user-id8}','{user-id9}','{user-id10}','{user-id11}','{user-id12}','{user-id13}','{user-id14}','{user-id15}')";
    });
    

    In Expand, I'm using $select to return only id of the group.

    If you have more than 15 users, you will need to make several calls.

    I suppose, you are using Graph C# SDK