How to apply an equality filter to a Users request?

Viewed 1527

I'm trying to make a call to the MS Graph Users API using C# and the GraphServiceClient. I'm trying to filter by Mail but no matter what format I try, it gets rejected due to an invalid query. I've tried all the examples I've found on the interwebs but I can't seem to find one that uses the service client to filter users by equality.

I've tried the following in Filter.

$"eq('Mail', '{email}')", $"equal('Mail', '{email}')", $"equals('Mail', '{email}')", and $"'Mail' eq '{email}'"

await _graphClient
    .Users
    .Request()
    .Filter(filter)
    .GetAsync();

I did find a way to filter users where my tenant is the issuer but I need to be able to also search for invited users as well.

var filter = $"Identities/any(id:id/Issuer eq '{TenantName}' and id/IssuerAssignedId eq '{emailAddress}')";

Removing the equality check on the TenantName makes it an invalid filter.

What am I doing wrong here; is it possible?

2 Answers

Here is the filter in my code for your reference:

var response = await graphClient.Users.Request().Filter("mail eq 'test@mail.com'").GetAsync();

The second option is to pass the email directly in URL:

https://graph.microsoft.com/v1.0/users/test@mail.com

Code:

var user = await graphClient.Users["test@mail.com"].Request().GetAsync();
Related