Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to filter Sharepoint List Items Queried with Microsoft Graph

I am using the .net SDK. Trying to filter a large list with Microsoft Graph,

My query works fine using .Items.Request().Expand("fields").GetAsync(); However, if I add a filter, it doesn't work as expected.

I have tried two approaches :

  1. Add .Expand("fields").Filter("fields/Archived eq false").GetAsync(); That works, but returns all the list items without filtering.

  2. Add .Expand("fields($filter=Archived eq false)").GetAsync(); This does not work - it gives me an error that expand, select, and filter are the only allowed queries.

What does work is ("fields($select=Archived)"), but of course, no filtering is done.

So how are we to query large lists using Microsoft Graph?

like image 708
JeffC Avatar asked Oct 28 '25 13:10

JeffC


2 Answers

You need to quote the value you pass into your filter: Fields/Archived eq 'false' (note the 's):

var result = graphClient
    .Sites["root"]
    .SiteWithPath("siteId")
    .Lists["listId"]
    .Items
    .Request()
    .Expand("Fields")
    .Filter("Fields/Archived eq 'false'");
like image 183
Marc LaFleur Avatar answered Oct 31 '25 02:10

Marc LaFleur


After too much research on this issue i found below solution and its working fine for me:

To Filter you need to add Header parameter as follow: Prefer : HonorNonIndexedQueriesWarningMayFailRandomly

And Graph api will be as follow: &$filter = Fields/Archived eq False

like image 21
Sanjay Makwana Avatar answered Oct 31 '25 02:10

Sanjay Makwana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!