Pagination
Most requests that return multiple records are paginated. There will be a section of links
with URLs to retrieve the first
, next
, previous
, and last
pages of records. Depending on how a response is paginated, it may include values for page
, total_pages
, total_entries
, next_page
, and previous_page
. If the response is using cursor based pagination, page
, next_page
, and previous_page
will always return null
for all but the first and last pages.
links
section of a response instead of constructing pagination links yourself.
Paginated response example
For example, to retrieve the first page of clients, you would make the following request:
curl "https://api.harvestapp.com/v2/clients" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Harvest-Account-Id: $ACCOUNT_ID" \
-H "User-Agent: MyApp ([email protected])"
Response:
In that response, you can see the included pagination metadata values. To retrieve the next page of clients, use the next
URL provided in the links
section:
curl "https://api.harvestapp.com/v2/clients?cursor=eyJhZnRlciI6eyJpZCI6MzAwN319&per_page=2000&ref=next_cursor" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Harvest-Account-Id: $ACCOUNT_ID" \
-H "User-Agent: MyApp ([email protected])"
Response:
To retrieve the final page of clients, use the last
URL provided in the links
section:
curl "https://api.harvestapp.com/v2/clients?page=3&per_page=2000&ref=last" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Harvest-Account-Id: $ACCOUNT_ID" \
-H "User-Agent: MyApp ([email protected])"
Response:
Pagination parameters
Paginated endpoints use the following optional parameters:
-
per_page
— The number of records to return per page.-
The default and maximum
per_page
value for API requests is2000
. If you want to receive the maximum number of records per page, do not provide a value — the default is always the maximum number supported. -
If you provide a value for
per_page
that is too large, you will receive a422 Unprocessable Entity
error code with anInvalid per_page parameter
error message.
-
-
page
orcursor
— An indicator for which page of records should be returned.-
The
page
andcursor
parameters are mutually exclusive and should not be used together. If both are provided,cursor
will take precedence. -
You should always avoid using these parameters directly, and instead rely on the values provided by the
first
,next
,previous
, andlast
URLs in thelinks
section of the response. They will dynamically usepage
orcursor
values to maximize performance of the endpoints for you.
-
per_page
parameter example
To retrieve fewer records than the maximum page size supported, add the per_page
parameter to the URL. For example, to retrieve the most recently created client:
curl "https://api.harvestapp.com/v2/clients?per_page=1" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Harvest-Account-Id: $ACCOUNT_ID" \
-H "User-Agent: MyApp ([email protected])"