Skip to main content

Overview

This recipe shows you how to retrieve every card from a board by paginating through pages of results until you get an empty response.

What you need

  • Your API key and board ID from Card Sources > API

Step 1: Fetch the first page

Cards are returned 200 at a time, starting at page 0.
const response = await fetch(
  "https://app.getaptly.com/api/aptlet/YOUR_BOARD_ID?page=0",
  {
    headers: { "x-token": "YOUR_API_KEY" },
  }
);

const cards = await response.json();
console.log(`Page 0: ${cards.length} cards`);

Step 2: Paginate until empty

Keep incrementing the page number until you receive an empty array. That signals you have retrieved everything.
async function getAllCards(boardId, apiKey) {
  const allCards = [];
  let page = 0;

  while (true) {
    const response = await fetch(
      `https://app.getaptly.com/api/aptlet/${boardId}?page=${page}`,
      {
        headers: { "x-token": apiKey },
      }
    );

    const cards = await response.json();

    if (cards.length === 0) break;

    allCards.push(...cards);
    console.log(`Fetched page ${page}: ${cards.length} cards`);
    page++;
  }

  console.log(`Total cards retrieved: ${allCards.length}`);
  return allCards;
}

const cards = await getAllCards("YOUR_BOARD_ID", "YOUR_API_KEY");

Step 3: Work with the data

Each card is a JSON object containing its _id and all field values.
[
  {
    "_id": "JShpBxEFgRmZnivTf",
    "Name": "Jane Smith",
    "Stage": "Active",
    "Email": "jane@example.com",
    "Unit": "4B"
  }
]
You can now filter, transform, or export the data as needed.

Things to watch out for

  • There is no total count or hasMore flag in the response. An empty array is the only signal that you have reached the end.
  • Cards are sorted by last updated time. If records are being updated while you paginate, you may see duplicates across pages. For a clean sync, consider using webhooks to capture changes in real time instead.
  • Add a small delay between page requests if you are fetching a very large board to avoid hitting rate limits.

Next steps