How do we use select inside an expanded collection on Microsoft Graph? - microsoft-graph-api

Following query in MS Graph Explorer displays signed-in user's profile and its manager Diego Siciliani
https://graph.microsoft.com/v1.0/me?$expand=manager
But you may notice in the response it is returning tons of attributes of manager object, as well. Some of these attributes are objects (such as assignedPlans) themselves and have their own attributes, as well.
Question: How can we filter the above query so it returns user profile (that it is already doing) along with ONLY the following attirbute value the user's manager: "displayName": "Diego Siciliani"
Remark: Following query returns the error shown below: https://graph.microsoft.com/v1.0/me?$expand=manager($select=displayName)
Invalid $select properties

Please use the below query to get user and his manager details
https://graph.microsoft.com/v1.0/users/userid?$expand=manager($levels=max;$select=id,displayName)&$select=id,displayName&$count=true
ConsistencyLevel eventual
Update https://graph.microsoft.com/v1.0/me?$expand=manager($levels=max;$select=displayName)&$count=true

It is known issue from Microsoft that nested $select combined with $expand doesn't work (i.e. $expand=some_path($select=some_field) does not work with Microsoft Graph API).
See: https://learn.microsoft.com/en-us/graph/known-issues#query-parameter-limitations
$expand:
No support for nextLink
No support for more than 1 level of expand
No support with extra parameters ($filter, $select)
I wish they would implement it because right now we either have to pull a lot of extra data (e.g. for managers), or we have to make a lot of requests per user to retrieve just the field we want.
There's a solution that deal with batch requesting but it requires a json solution: https://learn.microsoft.com/en-us/graph/json-batching?view=graph-rest-1.0

Related

How to retrieve from Microsoft Graph all users that are members of all 3 groups from my list in a single request?

I need to retrieve from Microsoft Graph all users that are members of all 3 groups from my list. How can I do that in a single request?
I would use $filter inside $expand of memberOf property on users' endpoint.
https://graph.microsoft.com/v1.0/users?$expand=memberOf($filter=id+eq+'{group1-id}' and id+eq+'{group2-id}' and id+eq+'{group3-id}')
But from my testing it looks like $filter is ignored, and all users are returned.
The second option
https://graph.microsoft.com/v1.0/users?$expand=memberOf&$filter=memberOf/any(r:r/id eq '{group1-id}' and r/id+eq+'{group2-id}' and r/id+eq+'{group3-id}')&$count=true
with request header ConsistencyLevel:eventual returns
the error Request_UnsupportedQuery with the message Multiple filter clauses are not supported on an 'Any' operation on a simple property.
Currently, there is no functional way how retrieve all users that are members of all specified groups.

Getting Groups with Guests via Graph

I'm trying to retrieve a list of Microsoft 365 Groups that have guest members via Graph.
I can get a full list of groups and then filter client-side, but the documentation says that the "members" property is queryable in the $filter clause, so I thought I'd be able to do something like this:
/beta/groups?$filter=members/any(x:x/userType eq 'Guest')
However, this is returning the following error:
Property 'members' does not exist as a declared property or extension property
Has anyone managed to pull this off? Or can someone confirm that it's not possible to filter a list of groups based on its members? Is there any way to do this without filtering client side?
Thanks!
Answering my own question, as I've heard from the PM in charge of this part of Graph.
https://twitter.com/merill/status/1550312453111955456?s=20&t=i9RNt7-E2fXNCSoDxESO4w
Unfortunately member is not available as a filter option for the group object so you will need to manually query each group.
Hopefully this gets added at some point, but for now I'm going to have to get the full list of groups and filter client-side.

Microsoft Graph api - Missing 'none' (or not any) functionality for $filter

I'm trying to retrieve any message that I haven't specifically categorized but there isn't a none filter option for Microsoft Graph. I tried to invert the any filter by using the following call:
/v1.0/me/messages?$filter=categories/any(c:c ne 'MyCategory')
However, this will still return items containing 'MyCategory'. Is there another method by which I can retrieve items that don't have that category set on them? (Returning items with no category set at all is not exclusive enough).
I had contemplated using custom extensions, however, the filter for extensions also lacks a none option.
try this
im not sure is this is your request
https://graph.microsoft.com/v1.0/me/messages/?$select=categories
There really isn't a good way to do negative comparisons like this within the API itself.
The reason any doesn't work is that your query translates to "include the message if any of it's categories are not 'MyCategory'". That would include messages with no categories (i.e. null) as well as message with any other category (i.e. a message with both MyCategory and Blue Category would match the filter).
Your best bet is using Open Extensions. These allow you to add application-specific data to Graph resources that you can filter against.

Select specific fields from users and expanded manager

I want to get manager relation for all users and this can easily be done with https://graph.microsoft.com/beta/users?expand=manager.
But I get all data on all users and all data for each manager, which is way too much! I want to limit my result set to only return id and displayName for user and only id on the manager relation.
https://graph.microsoft.com/beta/users?select=id,displayName&expand=manager(select=id)
This is not working and I get this error:
Term 'manager($select=id)' is not valid in a $select or $expand expression.
Any help is much appreciated.
Sad to say, I was looking for this as well - it seems that this is not supported:
https://developer.microsoft.com/en-us/graph/docs/concepts/query_parameters#expand-parameter
Not all resources or relationships support using $select on expanded items.
I think this means you cant use select on manager expand.
I would take it further even and say you cannot use select on the users query itself, since there is no way to include the expanded "manager" in the select, even with all its properties. Once you set a select statement your expanded manager property will be gone.
There are two choices at this point:
get the users without their manager, then create batch requests of 20 at a time to get the users managers (id only)
give up on trying to be efficient, and just get all users with their managers with all their properties. This would bloat your requests but you will get away with fewer requests.
I think depending on how much data you are planning to get (number of users, properties you need) you should choose the best way forward for you.
Here is graph API documentation that shows how to expand the entire management chain and return selected fields. Slight caveat that it works on the documentation page but it doesn't return the expected results at https://developer.microsoft.com/en-us/graph/graph-explorer.
https://graph.microsoft.com/v1.0/me?$expand=manager($levels=max;$select=id,displayName)&$select=id,displayName&$count=true
Link to graph API User List Manager:
https://learn.microsoft.com/en-us/graph/api/user-list-manager?view=graph-rest-1.0&tabs=http#code-try-8

Applying $filter option to GetRecentFiles call in MS Graph API

I'm using getRecentFiles MS Graph API and I'd like to filter out only certain file types (by file extension). However, when I try $filter query parameter it is ignored. Documentation on the method doesn't mention anything like this.
Is this behavior expected or is it a bug?
I believe that is expected as no OData query parameters link is not present on the page (when OData query parameters are supported, then its listed in a paragraph).
I have not managed to make it work, neither for drive item properties (eg. id, creation date) nor for nested properties (remoteItem/name or remoteItem/createdBy/user).

Resources