Tangocrypto
Search
K

Pagination

Learn about pagination and how you can use it to manage large requests.

What is pagination?

Some API endpoints paginate their responses to make the result set easier to handle. For example, if you request a list of objects that are potentially too large to run efficiently, the endpoint returns the first batch of results along with a cursor to access the next set of results.
The query results are divided into "pages" of 1 MB in size (or less) data. An application can process the first page of results, then the second page, etc. You include the cursor in subsequent requests to the endpoint as a URL query parameter of your request.
To determine whether there are more results and to retrieve them one page at a time, applications should do the following:
  1. 1.
    Make a request with the desired size and check the result, if the cursor is not empty, construct a new request with the same parameters as the previous one. However, this time, take the cursor value from the last query and use it as the cursor parameter in the new request.
  2. 2.
    If the cursor is empty in the result it means there are no more items to be retrieved.

Example

Let's make the following query with size=50
https://cardano-mainnet.tangocrypto.com/<app-id>/v1/nft/collections?size=50
In the response, we see the cursor with a non-empty value (showing only one record for simplicity)
{
"result": {
"collections": [
{
"id": "5f92c5e01c4848e4b6271a9bf48a3bd9",
"name": "Tango Collection",
"url": "https://www.tangocrypto.com",
"description": "Tango collection description",
"payout_address": "addr_test1qp9mj7vnenx4v99hw7ztfq03n7dmmujpgtlyfjhhel9w67nk72usllcew208n60ym94xcptfrgytuy5apwp565x28jgsg0ztq3",
"policy": {
"lock": true,
"lock_time": "2022-01-03T15:35:10.000Z",
"policy_id": "1373bf16cdea380e6c9c716d0f56f021b9e9ddea90b248dae6310d95",
"script": {
"type": "all",
"scripts": [
{
"type": "sig",
"keyHash": "ac1746df0ba039de81274d472a477fced610f57cebc5c7841074f54c"
},
{
"type": "before",
"slot": "46854826"
}
]
}
},
"metadata": {
"label": "721",
"asset_name": "<asset_name>",
"name": "<name>",
"image": "<image_link>",
"media_type": "<mime_type>",
"description": "<description>",
"attributes": {
"face": "<face>",
"twitter": "https://twitter.com/tango_crypto",
"copyright": "Tangocrypto 2021",
"color": "<color>",
"artist": "Tangocrypto",
"collection": "Tangocrypto Collection",
"body": "<body>",
"eyes": "<eyes>",
"accessory": "<accessory>"
},
"version": "1.0"
},
"created_at": "2021-11-30T21:04:09.897Z",
"updated_at": "2021-11-30T21:04:09.897Z"
}
],
"cursor": "a97f98a8c533ee55fc2c6897c9b50506dc8d65b921092e469f62f9d0e2d0dc92902605dba96d30b2e027557d3d6ea8cb3c1597d93e36f9c70771f19485f176607d834f6bc4fd664e0f68d4c28eff52cc298dee1dc17975c043d05903c31dae41ff84c779f1f8d2bcc00447e25d066a4e"
},
"status_code": 200
}
To retrieve the next batch of items we use the same query but now inserting the obtained cursor from the previous step as a the query parameter:
https://cardano-mainnet.tangocrypto.com/<app-id>/v1/nft/collections?size=50&cursor=a97f98a8c533ee55fc2c6897c9b50506dc8d65b921092e469f62f9d0e2d0dc92902605dba96d30b2e027557d3d6ea8cb3c1597d93e36f9c70771f19485f176607d834f6bc4fd664e0f68d4c28eff52cc298dee1dc17975c043d05903c31dae41ff84c779f1f8d2bcc00447e25d066a4e
This process can be repeated until the cursor is empty because there are no more items to retrieve.