Jeff Greene
Jeff Greene

Reputation: 310

MSGraph pagination fails with Invalid filter clause when filter used

Pagination appears not to work when an advanced filter is used? I'm able to get the first result set but the first call to users = await users.NextPageRequest.GetAsync(); fails with 'Invalid filter clause' If I don't use a filter then no problem.

queryOptions = new System.Collections.Generic.List<Option>
{
    new QueryOption("$count", "true"),
    new HeaderOption("ConsistencyLevel", "eventual")
};
filter = "startswith(companyName, 'US')";

List<User> allusers = new List<User>();
var users = await graphClient.Users
   .Request(queryOptions)
   .Filter(filter)
   .GetAsync();
while (users.Count > 0)
{
    allusers.AddRange(users);
    if (users.NextPageRequest != null)
    {
        users = await users.NextPageRequest.GetAsync();
    }
    else
    {
        break;
    }
}
return allusers;

Upvotes: 1

Views: 293

Answers (2)

DerOta
DerOta

Reputation: 157

I experienced this issue myself. Apparently, something broke with one of the new SDK version as it works for me with the Microsoft.Graph v3.0.0.

If it's no problem for you to work with an older version I would "downgrade" to a lower version where this works and wait for Microsoft to solve it.

I've created an issue on the msgraph-sdk-dotnet GitRepo in case you want to stay updated

Upvotes: 1

Shiva Keshav Varma
Shiva Keshav Varma

Reputation: 3595

Try this below code.

        List<Option> options = new List<Option>
        {
            new QueryOption("$count",
                  "true"),
           new QueryOption("$filter",
                  "startswith(companyName,'A')"),

           //Creating header
           new HeaderOption("ConsistencyLevel", "eventual")
        };

        try
        {
            IGraphServiceUsersCollectionPage users = await graphClient.Users
            .Request(options)
            .GetAsync();
        }
        catch(Exception e)
        {
            Console.WriteLine(e);
        }

It worked for me.

Upvotes: 0

Related Questions