Search code examples
c#asp.net-coremicrosoft-graph-apimicrosoft-graph-sdks

Microsoft graph get user by email or Mail


I need to query get a single user details through Microsoft graph by email id, can anyone help me I couldn't find it in MS docs.

var users = graphServiceClient.Users.Request().GetAsync().GetAwaiter().GetResult();

this brings only 100 users I need to get user by email so I can get specific user


Solution

  • Pls try this code.

    using Azure.Identity;
    using Microsoft.Graph;
    
    var scopes = new[] { "https://graph.microsoft.com/.default" };
    var tenantId = "hanxia.onmicrosoft.com";
    var clientId = "azure_ad_app_id";
    var clientSecret = "client_secret";
    var clientSecretCredential = new ClientSecretCredential(
        tenantId, clientId, clientSecret);
    var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
    var temp = await graphClient.Users.Request().Filter("mail eq 'tiny@outlook.com'").GetAsync();
    

    When we want to do a filter in Ms graph api, we may firstly check if the target property support filter, for ms user api, mail is supported.

    enter image description here