Pagination
In this guide, we will look at how to work with paginated responses when querying the 1ClickImpact API. By default, all responses limit results to 10. However, you can go as high as 1000 by adding a limit
parameter to your requests.
When an API response returns a list of objects (user_records
, customers
or customer_records
), no matter the amount, pagination is supported. In paginated responses, objects are present as a list and response has a cursor
attribute that indicates that you have NOT reached the end of the last page. If cursor
attribute is not present, it indicates that you have reached the end of the last page.
You can use the cursor
query parameter to browse pages.
Example using cursors
In this example, we make the first request for user_records
after start_date
"2023-10-02" and limit
3. As a result, we get a list of 3 user records and can tell by the cursor
attribute that we have NOT reached the end of all user records and there are more records.
- Name
start_date
- Type
- string
- Description
The start date from which point onwards you want to fetch user records.
- Name
limit
- Type
- integer
- Description
Limit the number of records returned.
- Name
cursor
- Type
- string
- Description
The
cursor
from the response can be used as query parameter in the second request to fetch the subsequent list of user records.
Second request
curl --location https://api.1clickimpact.com/v1/records?limit=3&cursor=eyJjcmVhdGVkT24iOiIyMDIzLTAQxMzgzMDYifQ==&start_date=2023-10-02 \
--header 'x-api-key: {PRODUCTION API KEY}'
First request
curl --location https://api.1clickimpact.com/v1/records?limit=3&start_date=2023-10-02 \
--header 'x-api-key: {PRODUCTION API KEY}'
Paginated response for first request
{
"user_records": [
{
"user_id": "U123",
"time_utc": "2023-10-04T20:56:15.031Z",
"tree_planted": 24,
"waste_removed": 0,
"carbon_captured": 0,
"money_donated": 0
},
{
"user_id": "U123",
"time_utc": "2023-10-04T20:57:20.040Z",
"tree_planted": 0,
"waste_removed": 67,
"carbon_captured": 0,
"money_donated": 0
},
{
"user_id": "U123",
"time_utc": "2023-10-06T20:56:25.009Z",
"tree_planted": 0,
"waste_removed": 0,
"carbon_captured": 31,
"money_donated": 0
}
],
"cursor": "eyJjcmVhdGVkT24iOiIyMDIzLTAQxMzgzMDYifQ=="
}