Pagination example for greater than 2000 Records in AtTask API

1.2k Views Asked by At

In AtTask API Calls, How do I use Pagination when I need More than 2000 records to return?
For example, given the following off of the Developers Site of https://developers.attask.com/api-docs/#Basics I see the following

Paginated Responses

To override the default number of results and set the response to provide 200 results you would include the following in your query:

GET /attask/api/project/search?$$LIMIT=200

To ensure reliability and performance for other tenants in the system, the maximum allowed limit per query is 2000 objects. Attempting to specify a larger limit will result in an error.

Therefore, it is recommended you consider using paginated responses for large datasets. To specify the first result that should be returned, the $$FIRST filter can be added. The following will return results 201-250 for a query.

GET /attask/api/project/search?$$FIRST=201&$$LIMIT=50

What I'm not understanding is how to figure out how many I have in the first place. If I am looking to download the hours in the system, how do I know how many times I have to call (is there a count(*)) or some method like that? Am I simply going to get the first 2k, process, attempt to get the next 2k, and process if not empty? Rinse and repeat?

2

There are 2 best solutions below

1
On

Since the initial search will only pull 2000 results you will have to iterate and pull the next 2000 until there are no results left.

0
On

You can get the total count of items using a report call. So in your example, to get the number of hour objects in the system (NOT the summed total hours), you could do the following:

/attask/api/HOUR/report?ID_AggFunc=count

Hope that helps!