I know how to get member directory roles filtering by type using the rest query below:
https://graph.microsoft.com/v1.0/me/memberOf/$/microsoft.graph.directoryRole
So the response from MS Graph api only contains directoryRole
objects. Not sure how this can be done using the MS Graph .Net client SDK as we do not specify any OData keyword like Select
or Filter
in the actual Rest request.
Note that I do not want to call just memberOf
and filter directoryRole
type responses in memory on client side, I want this filter to be part of the query as in the URL above, so memberOf
response contains only directoryRole
s.
With the SDK, filtering is a function applied to the object. For example:
Unfortunately, this won't help you here since
/memberOf
doesn't support$filter
. So you would need to do the filtering on the client.If you're checking a specific
directoryRole
, you could come at this from the other direction. The/members
endpoint does support filtering by memberid
:It is important to note here that
/members
does not support filtering byuserPrincipalName
, only by the actualid
.The Graph Net Client have not directly support your requirement.
But based on my test, we can try the following work around:
Use the following code to get the list with DirectoryRole and then filter by DisplayName, and then check the role template id(For the directoryRole from Me.MemberOf, if the DisplayName contains Administrator, basically, we are admin role. If use the DirectoryRoles api, we can iterate the list and check the role template id):
Results of Me.MemberOf: Results of DirectoryRoles:
If the work around still cannot suit your requirement, I suggest you submit an feature request on uservoice and github issues
Supplementary answer: (Unfortunately the filtering is generally pretty limited in Microsoft Graph for directory resources. So you can just use the client side in-memory filter or submit feature request now):
Theoretically, we can use the rest api like this(The specified filter to the reference property query is currently not supported.)
And in the C# code which is based on the Graph Client