Search code examples
c#microsoft-graph-apimicrosoft-graph-sdks

Microsoft Graph API get multiple B2C user via email address


I have the use case to query multiple b2c user from the microsoft graph api to get the display name and get the information about the last login. I am aware that the last login is just available via the beta route.

I am using the microsoft graph api beta client and try to get a user via an email address.

My b2c users do not have any mail or otherMail values, only information about the email is placed in the identities list.

var result = await client.Users
.Request()
.Select(e => new
{
    e.DisplayName,
    e.UserType,
    e.OtherMails,
    e.UserPrincipalName,
    e.Mail,
    e.Identities,
    e.SignInActivity
}).GetAsync();

This Call returns all user, so I would have to filter in memory which would be bad.

.Filter("identities/any(id:id/issuer eq 'xxx.onmicrosoft.com' and id/issuerAssignedId eq 'superUser@mail.com')")

This filter function returns exactly one specific user, but I wasn't able to query multiple users via a single request. Something like .Filter("identities/any(id:id/issuer eq 'xxx.onmicrosoft.com' and id/issuerAssignedId eq 'superUser@mail.com') or identities/any(id:id/issuer eq 'xxx.onmicrosoft.com' and id/issuerAssignedId eq 'superUser2@mail.com')") Return query is to complex an replace the 'eq' with an 'in' returns not supported query, because looks like lambda operators do not support 'in'.

Has someone an idea how to query for e.g. 2 emails addresses with an single request?


Solution

  • Thanks Danstan,

    with the a batch request it works to get with single request up to 20 accounts at once. https://learn.microsoft.com/en-us/graph/sdks/batch-requests?tabs=csharp#simple-batching-example The API still limited it to 20 request in a single batch request. 'Code: MaximumValueExceeded Message: Number of batch request steps exceeds the maximum value of 20.'

    This makes it possible to query all the data by view requests.