microsoft-graph-apisharepoint-online

Filter List Item from MS Graph API Response


I am trying to filter items when searching a SharePoint list, via the Microsoft Graph API, where certain custom field values are met, and the content type is not a folder. For example:

/sites/mysite.sharepoint.com/lists/test/items?&select=name,contentType,webUrl,id&$expand=driveItem,fields&$filter=fields/MyColumn eq 'HelloWorld' and fields/ContentType ne 'Folder'

Both the custom field and Content Type are indexed, but I still receive the below response:

{
    "error": {
        "code": "invalidRequest",
        "message": "Field 'ContentType' 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 have used the above Prefer header, and that does return data, but it seems wrong that I have to supply such a value when the column is indexed. Is there something I am missing with this, or is there a compatibility problem with the Content Type column within the Microsoft Graph API? If there is, how can I work around it without having to use the Prefer header?


Solution

  • You need to provide the allowthrottleablequeries preference to execute this query, so you must provide request headers for this endpoint.

    https://graph.microsoft.com/v1.0/sites/{site id}/lists/{list id}/items?$select=name,contentType,webUrl,id&$expand=driveItem,fields&$filter=fields/MyColumn eq 'HelloWorld' and fields/ContentType ne 'Folder'
    
    Prefer: allowthrottleablequeries