Philip Young
Philip Young

Reputation: 107

Microsoft Graph API / C# SDK can't find Security Group by Display Name

I am using the Microsoft .NET Graph SDK to query Groups with the query listed below (passing in searchText to search by Display Name). I've noticed a Group is not coming back in the results despite the correct query parameter and I'm trying to figure out why.

The Group is a Security Group of Source 'Cloud' that was created in January 2014 if that helps. I've been able to successfully query other Groups in this Tenant of this type just fine, I am wondering if there is a property I am missing or if maybe older Groups can't be queried this way?

var groups = await graphClient.Groups
  .Request()
  .Filter($"startsWith(displayName,'{searchText}')")
  .Select(g => new
  {
    g.Id,
    g.DisplayName,
  })
  .Top(10)
  .GetAsync();

Upvotes: 0

Views: 658

Answers (1)

Philip Young
Philip Young

Reputation: 107

Ok, so after using Graph Explorer I was able to find the Group by Object Id, and after doing a query of the Group by Object Id using the GraphClient above I was able to figure out what was wrong. There was a space in front of the Display Name of the Group ie: " GroupName". So when querying by Display Name and StartsWith, what is passed in is taken quite literally with no trimming. Searching by display name with the above code and the space in the front worked to find the Group.

Upvotes: 1

Related Questions