Microsoft Graph HonorNonIndexedQueriesWarningMayFailRandomly Error when filtering SharePoint Online lists - microsoft-graph-api

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

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.

Graph query on SharePoint Libraray with Paging

I have libraries containing way more than 5000 files
When using:
https://graph.microsoft.com/v1.0/sites/3a8180fe-ca21-40a8-81e6-0950f5966f07/lists/DPC Documents/Items?top=499&$expand=fields&$filter=fields/FileLeafRef eq '0100.009_Client Name_Physician Name_FMV Exhibits_466689.XLSX'
I Get error "The request is unprocessable because it uses too many resources"
I can I ask for it to be paged?
BTW equivalent SharePoint REST call returns "The attempted operation is prohibited because it exceeds the list view threshold."
So there is no way to look for items in lists containing more than 5000 items.
I noticed I can't publish major version programmatically in such libraries.
I MS not supporting any API to work with this?
Thanks
This is most probably due to the reason that you have more than 5000 files in the doc library and the filter column FileLeafRef is not indexed (you cannot add index this column either). I encountered same error when filtering with a custom metadata column but fortunately after adding the index to the column, the error went away. The only solution to your problem is not to use FileLeafRef as your filter column but use the Title column in the filter condition, after ensuring that Title column is populated with name of the document and the column is indexed.

How to get List Items from sharepoint using Graph API

I want to get a collection of ListItem from a Sharepoint List (O365) using Microsoft Graph. I have used the following URI but it is returninga "Bad Request" error.
https://graph.microsoft.com/beta/sites/{id}/lists/{id}/items/{id}?expand=fields(select=Title,Product)
First, you really shouldn't use the /beta Graph in production code. It is not stable and breaking changes can (and do) happen without warning. Unless you have a very specific need, always use /v1.0.
I believe your problem here is that you're attempting to select Title from the Fields collection. This property isn't actually a member of Fields, it is part of the ListItem itself. Try this instead:
?$select=title,fields&$expand=$fields($select=product)

Provide the 'allowthrottleablequeries' preference to allow this

I have developed an API using Microsoft Graph API. I am encountering below issue.
URL that I am calling :
/v1.0/sites/root/lists/cb32cc85-5351-423d-b2ec-bb418c1d9c64/items?
$filter=fields/Created gt '2018-1-1T00:00:00'
&expand=fields
&$orderby=createdDateTime
&$top=10
Error returned from the API :
Field 'Created' 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.
How to enable allowthrottleablequeries as it says and how should I achieve this?
I'm afraid this isn't a very clear or useful error message. As far as I know, there isn't actually a way to enable allowthrottleablequeries.
This happens when a SharePoint list grows too large to handle filtering or sorting non-indexed columns. The fix is to add an index to the created column in your List Settings. You can find instructions on how to accomplish this in Add an index to a SharePoint column.
Try to send your request with following Request Header
Prefer: allowthrottleablequeries
If it does not work then try the following Request Header
Prefer: HonorNonIndexedQueriesWarningMayFailRandomly

Select fields on Microsoft Graph list of Messages

I'm using Microsoft Graph to get a list of messages for a user.
I'm using the following URL
https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages
One important thing that is returned by this is the meetingMessageType when the message revolves around a meeting request.
I would also like to get the uniqueBody of the message. However, that's not provided by default. One needs to specifically ask for that field. I can do that by adding ?$select=uniqueBody to the URL.
However, that now means that I need to add the rest of the fields I want to the $select query parameter. That's not a big deal until I run into meetingMessageType. Microsoft Graph returns:
Could not find a property named 'meetingMessageType' on type 'Microsoft.OutlookServices.Message'.
What can I do to ensure I get both uniqueBody and meetingMessageType?
Try this:
$select=uniqueBody, microsoft.graph.eventMessage/meetingMessageType
Yogesh's answer is close but will result in a Only one level select is supported error.
As long as you don't care about the value of meetingMessageType, you can use this select:
$select=microsoft.graph.eventMessage, uniqueBody
You'll note that the results no longer include meetingMessageType as a property. The list however is limited to only those messages that are eventMessage, effectively giving you a result set filtered to only show meeting requests.

Resources