Search code examples
trello

How to paginate Trello api response?


I am using Trello's API to pull the boards and their cards.

I've noticed one of the boards I am pulling is approaching thousand cards at the moment, so I wonder how to paginate the results?

I tried using the since attribute and feed last card's update time into it, but afterwards I get zero results, so I must be doing somethign wrong.

The api documentation doesn't say much and the API response I've tried is very confusing:

/boards/xyz/cards?limit=1&before=2015-1-1

returns card which activity is after specified date.

"dateLastActivity"=>"2015-02-03T17:51:23.253Z",

and there is no other date field I could use to continue pagination.


Solution

  • ​You are right in your assessment. The before and since parameters operate on card creation date. Because we use standard Mongo IDs, you can actually derive the Card creation date from the Card ID. (Here is one such tool: https://steveridout.github.io/mongo-object-time/)

    ​ ​As a convenience, Trello also allows you to pass in a Card ID to the before and since parameters and we will use the date for you. The recommended way of paging through a large set of cards is to repeat the same query, and use these parameters to move forward or backward.