Share via

Unexpected behavior when getting azure groups

Gleb Prigozhinski 0 Reputation points
2024-02-28T09:28:54.11+00:00

Describe the bug The Azure Graph API sends data without sorting according to the matching condition of the search criteria. On the Azure portal, records are returned correctly. There is inconsistent behavior.

Additional context When I try to find a group using "/groups?$search="displayName:name"&top=10", I do not get the group I am looking for in the list of found groups. This is because my group is much lower in the list compared to those that come in response. That is, the sorting by exact match does not work. However, if I go to the Azure website and try searching through the interface, my group comes first. But the Azure website uses a $batch POST request. Why is the behavior different? I've tried v1.0 and beta, and the behavior is the same.

To Reproduce CASE 1: Steps to reproduce the behavior:

  1. Go to https://developer.microsoft.com/en-us/graph/graph-explorer
  2. Fill the request https://graph.microsoft.com/v1.0/groups?$search="displayName:some-name"
  3. Click by 'Run query'
  4. See response

Expected behavior The first element of the array is the record with the best match based on the displayName field.

Actual behavior The most matching record is located at the end of the list.

CASE 2: Steps to reproduce the behavior:

  1. Go to https://developer.microsoft.com/en-us/graph/graph-explorer
  2. Fill the request https://graph.microsoft.com/v1.0/groups?$search="displayName:some-name&top=1"
  3. Click by 'Run query'
  4. See response

Expected behavior I see the record I am looking for.

Actual behavior I see another record...

For example, I try to find 'hello-word-group', but I receive next response:

[{
displayName: '123213-hello-word-group'
},{
displayName: '7734743-hello-word-group-4374348'
},{
displayName: 'hello-word-group'
}]

And if I limit entries, I won’t see the group.

Could you please advise if I might be doing something incorrectly and if there's another flag I need to send? Thank you.

Microsoft Security | Microsoft Graph
0 comments No comments

1 answer

Sort by: Most helpful
  1. Carolyne-3676 1,136 Reputation points
    2024-03-05T07:07:32.1933333+00:00

    The search returns all results containing the search string and the order of the results is not guaranteed to be in order of the best match. If you are looking for an exact match, I would suggest using the $filter query parameter. This will return only groups where the displayName is exactly 'some-name'. Additionally, you can use the $top parameter to limit the number of results. Helpful Documentation

    https://graph.microsoft.com/v1.0/groups?$filter=displayName eq 'some-name'
    
    

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.