Filtering on recent files Microsoft Graph API not working - microsoft-graph-api

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.

Related

Search calendarview events by title and attendee email with Microsoft Graph

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.

Is it possible to search for messages with a matching substring in body and also a matching date?

I would like to, in a single request, get a list of messages filtered by date and by content in the body (if it's possible, of course).
I'm perfectly able to receive an ok response (200) from the following endpoint:
https://graph.microsoft.com/v1.0/users/user#company.com/messages?search="body:substring"
However, this gives me a broad response, since I'm interested only in cases between a specific week. Also, it's impossible to use a filter parameter along with the search one.
Then, in regard to the date filter, I could use:
https://graph.microsoft.com/v1.0/users/user#company.com/messages?$filter=(sentDateTime ge 2000-01-01) and (sentDateTime le 2100-01-01)
The problem is: I cannot filter the body as well, since I receive an error 400 - 'Bad Request: Invalid filter clause':
https://graph.microsoft.com/v1.0/users/user#company.com/messages?$filter=contains(body, substring)
Right now, my work around is: I request all the messages from user#company.com regarding a specific week, and after receiving that response, I locally filter the body in my machine. This works, but is not as fast as a compound request.
You can include specific a date restriction within your KQL Search eg
https://graph.microsoft.com/v1.0/me/messages?$search="(sent>=2019-01-01 AND sent<=2019-02-01) AND (body:asx)"
That should yield better performance then a filter

How to filter Outlook events by content

I want to get a list of Outlook events over the Graph API and filter them by searching for some text in the events body.
I was able to filter by subject like this:
https://graph.microsoft.com/v1.0/me/calendar/events?$filter=contains(subject,'test')
But if I try this with the body it does not work. The returned error message is either 'Invalid filter clause' or it says that an internal server error occurred. I understand that the body property of the event is not of type string, but it should be possible somehow to search in its content property
I already tried the following:
https://graph.microsoft.com/v1.0/me/calendar/events?$filter=contains(body,'test')
This returns 'Invalid filter clause'
https://graph.microsoft.com/v1.0/me/calendar/events?$filter=contains(body/content,'test')
Returns 'An internal server error occurred'
As far as I know Microsoft Graph does not support filtering for the field body

How to filter by value of an extension in Microsoft Graph?

I am trying to save some data to events using open extensions, and retrieve an event by the value of the extension I saved. I unfortunately couldn't find any documentation around it, and not sure if it is possible.
I am sure that the extensions are saved properly because when I use make a request to this URL in graph explorer it returns the data properly attached to the events:
https://graph.microsoft.com/v1.0/me/calendars/{calendarId}/events?$filter=Extensions/any(f:f/id eq 'Com.MyCompany.prop_id')&$expand=Extensions($filter=id eq 'Com.MyCompany.prop_id')
Now what I want to do is to filter upon the value of the extension. For example, if I have 3 events that I created, I have different Com.MyCompany.prop_id values for each of them, say 1,2,3. What I want to do is to get back only the event with Com.MyCompany.prop_id = 3.
My tries:
https://graph.microsoft.com/v1.0/me/calendars/{calendarId}/events?$filter=Extensions/any(f:f/value eq '3')&$expand=Extensions($filter=id eq 'Com.MyCompany.prop_id')
and
https://graph.microsoft.com/v1.0/me/calendars/{calendarId}/events?$filter=Extensions/any(f:f/id eq 'Com.MyCompany.prop_id' and f/value eq '3')&$expand=Extensions($filter=id eq 'Com.MyCompany.prop_id'), and some other tries that I don't remember.
Most of them returned RequestBroker--ParseUri: Could not find a property named 'value' on type 'Microsoft.OutlookServices.Extension'. or some other error.
I appreciate any help.

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