Search calendarview events by title and attendee email with Microsoft Graph - microsoft-graph-api

I am trying to implement a search on top of the Microsoft Graph calendarview API to provide feature parity with Google Calendar search, where the search term will return results with a matching event subject, or attendee name/email.
I am able to implement subject search with
$filter=contains(subject, '<query'>)
however, I have been unable to figure out how to return results with matching attendee name/email.
I have tried
$filter=contains(subject, '<term>') OR attendees/any(a: contains(a/emailAddress/address, '<term>'))
but get the error:
The query filter contains one or more invalid nodes.
I tried using eq instead
$filter=contains(subject, '<term>') OR attendees/any(a: a/emailAddress/address eq '<term>')
but then get the error:
An internal server error occurred. The operation failed.
I also tried using
$search="<term>"
this returns no error, but doesn't filter the results at all.
Is it possible to search for calendar events with matching title or attendee, using this, or another, api?

According this comment Graph API doesn't support drilling down multiple levels of relationships.

Related

Filtering on recent files Microsoft Graph API not working

I am trying to fetch recently accessed items for a user using this endpoint. While fetching the items themselves works, I am unable to filter on lastModifiedDateTime, which is a property of the API response, as per this link.
I am making a GET request to the following endpoint:
https://graph.microsoft.com/v1.0/me/drive/recent?$filter=lastModifiedDateTime ge 2020-08-25T05:30:00Z
And I am getting a Microsoft.SharePoint.Client.InvalidClientQueryException with the following message:
'The expression "lastModifiedDateTime ge 2020-08-25T05:30:00Z" is not valid.'
Please help!
The error which is showing up says 'The expression "lastModifiedDateTime ge 2020-08-25T05:30:00Z" is not valid' which means the expression which you have given in the filter is not right. You need to correct it as shown below.
https://graph.microsoft.com/v1.0/me/drive/recent?$filter=lastModifiedDateTime ge '2020-08-25T05:30:00Z'
But still this call doen't work because the filter is not supported on this property and you will end up 'Invalid filter clause'.
As a work around you can get the recent files and filter it on your end as most of the properties doesn't support filtering yet.

Expanding and Filtering MS Graph API Does Not Work

I need to get an eventMessage from a user's mailbox that is associated with a specific event.
I have the event's iCalUId but I am unable to filter on it:
/users/${roomEmailAddress}/messages
?$expand=microsoft.graph.eventMessage/event($filter=iCalUId eq '${iCalUId}')
What I am trying to do is get all messages, then expand so that I see the events associated with each message, then filter each event to find the one I care about.
However, I get a response with all events and the filtering mechanism is not working.
Where am I going wrong?
Graph doesn't support including a $filter in the $expand. From the documentation:
$expand:
No support for nextLink
No support for more than 1 level of expand
No support with extra parameters ($filter, $select)
What you can do is leverage the $search parameter to parameter to find all of the event messages ($search="kind:meetings) and then $expand the associated event:
/me/messages?$search="kind:meetings"&$expand=microsoft.graph.eventMessage/event
This worked for me, first I filtered then I expanded list
https://graph.microsoft.com/v1.0/sites/{sideID}/lists/{listID}/items?$filter=fields/{Name of Field} eq '{VALUE}'&$expand=fields

Unexpected results when filtering security alerts by createdDateTime

I'm seeing some unexpected behavior from the Microsoft Graph Security Alerts APIin the Graph API.
When filtering by createdDateTime, when no results are expected, it is returning results for today instead of an empty array (as expected).
/beta/security/alerts?$filter=createdDateTime ge 2020-07-26T18:09:31Z
If the filter is changed to eventDateTime, the expected empty array is returned:
/beta/security/alerts?$filter=eventDateTime ge 2020-07-26T18:09:31Z
I'm seeing this on multiple accounts, but not in the Graph API Explorer.
This happens in the beta as well as v1.0 API.
Please reach out to us at graphsecfeedback_at_microsoft_dot_com with your tenant ID and json alerts seen for the createdDateTime filter query so that we can investigate further.

How to search users in Microsoft Graph SDK with C#?

In my C# application, I am using Microsoft Graph SDK with Azure AD implementation.
Please suggest me how to search users in my organisations (global contacts) based on search parameters .
For example , if "Raj" is the search parameter, I should be able to get all users with their name contains "Raj" or email address contains "Raj".
I found this method to get all users - "graphClient.Users.Request().GetAsync();". but, with this method limited response, I am not getting what exactly I want to search.
Thanks,
Shashidhar
Adding to the previous answer: to accomplish this through the Graph C# SDK, use the Filter() method:
graphClient.Users.Request().Filter("startsWith(displayName, 'k')").GetAsync()
You can use other methods on the request to customize the request, e.g. Select(), etc.
According to your description, I assume you want to search the users by using the search parameters.
Based on this document, we can currently search only message and person collections.
And I have tried the filter query parameter, the parameter is currently not supported the contains operator from this document. So if you want to search the user with name or the email address, we can use the startswith operator only.Like this:
https://graph.microsoft.com/v1.0/users?$filter=startswith(displayName,'k') or startswith(mail,'k')
It will find the user's diplayName or mail which is start with the k

Microsoft Graph HonorNonIndexedQueriesWarningMayFailRandomly Error when filtering SharePoint Online lists

I'm using ms-graph with SharePoint Online.
I've a simple list with a single title column and 3 items.
I use the following ms-graph call to filter items by title:
https://graph.microsoft.com/v1.0/sites/root:/lists/list-guid/items?expand=fields&filter=startswith(fields/Title,%27fig%27)
The result is an error message:
Field 'Title' cannot be referenced in filter or orderby as it is not indexed. Provide the 'Prefer: HonorNonIndexedQueriesWarningMayFailRandomly' header to allow this, but be warned that such queries may fail on large lists.
I know that this call was working before and also when I use SharePoint REST API then I can filter the list without any problems. I also tried different tenants.
Another fact is that the same call is working without the startswith filter.
Few days ago I had a different message for the same call.
"Field 'Title' cannot be referenced in filter or orderby as it is not indexed. Provide the 'allowthrottleablequeries' preference to allow this, but be warned that such queries may fail on large lists."
Regarding the following error:
Field 'Title' cannot be referenced in filter or orderby as it is not
indexed. Provide the 'Prefer:
HonorNonIndexedQueriesWarningMayFailRandomly' header to allow this,
but be warned that such queries may fail on large lists.
at least two options are available to surpass this error while filtering.
Option 1. Add an index to a SharePoint column
Once the index to a SharePoint column which participates in filtering is created, the error should no longer appear.
Option 2. Append header Prefer:HonorNonIndexedQueriesWarningMayFailRandomly
As the error message states append the specified header to request, for example in Graph Explorer:
Just checked the Graph API Explorer and found out that you can use allowthrottleablequeries rather than HonorNonIndexedQueriesWarningMayFailRandomly
Try to send your request with the following Request Header
Prefer: allowthrottleablequeries

Resources