invantive documentationpart of invantive cloud
Invantive Support ForumsLog In / Sign Up

Count Rows

The $count system query option with the value true answers how many rows a request would retrieve, without retrieving them.

Request

GET .../odata4/ExactOnlineREST.Financial.GLAccountsBulk@eol?$count=true

Answer

The answer is the number itself, as the whole body:

1284

This differs from the OData standard, which asks for a collection carrying @odata.count beside the rows. A request on this service therefore asks either for the rows or for their number, never for both at once. The /$count path segment is not offered either; the system query option is the way.

Counting a Selection

A filter counts with the request, so the number is the number of rows the same filter would retrieve:

GET .../odata4/ExactOnlineREST.Financial.GLAccountsBulk@eol?$filter=Division eq 920474&$count=true

Counting the Groups

Beside a grouping the number answered is the number of groups rather than the number of rows:

GET .../odata4/ExactOnlineREST.Financial.GLAccountsBulk@eol?$apply=groupby((DivisionName),aggregate($count as Accounts))&$count=true

That makes it a cheap way to find out how large a grouped answer will be before asking for it. A $top next to it has no effect on the number, because the number of a collection is the number before a limit is taken from it.

When To Use It

A row count is useful to size a download before starting it, and to check afterwards that a report received everything. It is not free: the platform still has to work out the number, and on a platform without a counting facility that means reading the rows. A count therefore counts against the Fair Use Limits like any other request.

Release Notes