When limiting the result sets that you work within Dynamics it is important to understand the distinction between Top and MaxPageSize.
If you are trying to limit the number of records you return within a call, you can use Top in your query to tell the system that you only want that specific, total number of results returned.
The syntax for this very straight forward and only involves appending “&$top=100” to your query where 100 is the total number of results we want to have returned to us.
Within that limited record result set, we can also specify the page size to be returned to us to handle those records. For instance, if I were to limit my total results to 2,500 contacts (when 50,000 exist in the system), I could implement a max page size for those 2,500 records of 500 records per page. This means that when querying data, the resultset for the 2,500 records would come back in 5 500 record batches to my code.
To implement the MaxPageSize you need to append this to the headers on your HTTPClient that is requesting the data to be retrieved. This takes a format to the below implementation where we have specified the maxpagesize to be 500 records.
Both Top and MaxPageSize are useful to ensure you are always returning what you need, when you need it.