I am calling Graph with the SDK in C#, my initial request works fine and I get 200 results but the iterator returns an error with an invalid filter clause.

The initial call with the filter works perfectly am I calling the iterator correctly?

DateTime date = DateTime.Now.AddDays(-25);
Date graphDate = new Date(date.Year, date.Month, date.Day);
string weekendingFilterdate = graphDate.ToString();

string timesheetItemFilterString = $"Fields/FridayDate eq '{weekendingFilterdate}'";
var resultsList = new List<ListItem>();
            var results = await _graphServiceClient.Sites[siteName].Lists[listName].Items.Request().Expand("fields").Filter(filterString).GetAsync();
            var pageIterator = PageIterator<ListItem>.CreatePageIterator(_graphServiceClient, results, (i) => { resultsList.Add(i); return true; });
            await pageIterator.IterateAsync();
        catch (Exception ex)
        return resultsList;

Error = {Code: BadRequest
Message: Invalid filter clause
Inner error:
    date: 2021-08-10T08:15:21
    request-id: 3fd61829-ab4e-4acc-bd37-f9064a0296f2
    client-request-id: 3fd61829-ab4e-4acc-bd37-f9064a0296f2
ClientRequestId: 3fd61829-ab4e-4acc-b...

1 Answer 1


This is an issue caused by the encoding of nextlink URL returned from the API endbpoint by the client library. This affects 4.x.x version of the sdk.

This is currently being worked on and should be fixed by the end of the week with the next release of the client library.

For now, you can work around this by using the requestConfigurator parameter of the pageIterator as follows.

Func<IBaseRequest, IBaseRequest> requestConfigurator = (request) =>
    // Replace filter clause from server with our original filter clause
    var newFilter = request.QueryOptions.FirstOrDefault(x => x.Name.EndsWith("filter"));
    if (newFilter != null)
        var index = request.QueryOptions.IndexOf(newFilter);
        request.QueryOptions[index] = new QueryOption(newFilter.Name, newFilter.Value.Replace("+", " "));
    return request;

var pageIterator = PageIterator<User>.CreatePageIterator(graphServiceClient, result, (i) => { resultsList.Add(i); return true; }, requestConfigurator);
await pageIterator.IterateAsync();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.