4

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?

Hury Shen
  • 14,948
  • 1
  • 9
  • 18
ChiefTwoPencils
  • 13,548
  • 8
  • 49
  • 75

2 Answers2

6

Here is the filter in my code for your reference:

var response = await graphClient.Users.Request().Filter("mail eq 'test@mail.com'").GetAsync();
Hury Shen
  • 14,948
  • 1
  • 9
  • 18
1

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();
user2250152
  • 14,658
  • 4
  • 33
  • 57
  • I tried that and it couldn't find external users by actual email: "Resource 'some@example.com' does not exist or one of its queried reference-property objects are not present." That's without any filtering applied. However, giving it the principal name worked though that's less than ideal due to having to manipulate external emails into the ugly principal name value. `some_example#EXT#@my.domain.com`, for example. – ChiefTwoPencils Feb 02 '21 at 17:16