I'm trying to get a count of list items in a Sharepoint Online list but Graph throw an exception with the following message "invalidRequest - $count is not supported on this API. Only URLs returned by the API can be used to page."
It's not possible to do this operation with a sharepoint list?
public async Task<int> GetListItemsCountAsync(string siteId, string listId, List<QueryOption> queryOptions)
{
queryOptions ??= new List<QueryOption>();
var countQueryOption = new QueryOption("count", "true");
queryOptions.Add(countQueryOption);
var listItems = await _graphService.Client
.Sites[siteId]
.Lists[listId]
.Items
.Request(queryOptions)
.GetAsync();
return (listItems?.Count ?? 0);
}
Another option could be to get all the elements of the list and use the Count property of the resulting collection. But the performance of this approach seems worse.