Pagination

Some responses from the Datagarden API are paginated. The endpoint documentation will indicate whether pagination is used. This page explains how pagination works in the Datagarden API.

Pagination for GET Requests

Paginated GET responses include pagination metadata, even when the response contains fewer objects than the pagination threshold. The actual data objects are returned in an array under the "results" key.

				
{
	"count": 200,
	"next": "http://api.the-datagarden.io/country/?page=2",
	"previous": null,
	"results": [
		{...},
		{...}
	]
}				
	  		

In the example above, with 200 total objects, multiple requests are needed to fetch all data. The URL for the next request is provided in the "next" attribute. While the total number of pages isn't shown, when "next" is null, you've reached the last page.

Pagination for POST Requests

POST request responses vary in size depending on your query. For example, requesting economic data for a single country returns a small response, while data for all ZIP code regions in a country can be very large. The Datagarden API automatically paginates responses larger than 2MB (uncompressed). A pagination object in the response indicates that the results are paginated.

				  	# Pagination object in response to POST method
  {
	"pagination": {
        "page": 5,
        "total_pages": 9,
        "next_page": 6,
        "previous_page": 4
    },
	"data_by_region": [
		{...},
		{...}
	],
	"params": {..}
  }					
				

The response above is an example response from a paginated POST request. The response to the request has in total 9 pages. The `next_page` attribute can be used to create the request to the next page. This can be done by simply adding
{"pagination": {"page": 6}}
to the payload of the request and making the request again. If the pagination object is not returned your response is not paginated and you can safely assume the result object contains all the records you requested.

Note that pagination only applies to the top-level list of region objects. The data within each region object (such as monthly economic data) is always returned complete in a single response. For example, if you request 5 years of monthly economic data for a region, all 60 months of data for that region will be returned together, while the regions themselves may be split across multiple pages.