Pagination

The SDK provides two approaches to pagination: manual control via list() and automatic iteration via listAll().


list()

Manual Pagination

All list() methods accept skip and take parameters for manual pagination. The response includes a meta.count field with the total number of matching records.

Parameters

  • Name
    skip
    Type
    integer
    Description

    Number of records to skip. Defaults to 0.

  • Name
    take
    Type
    integer
    Description

    Number of records to return. Defaults to 25.

Response Meta

  • Name
    meta.count
    Type
    integer
    Description

    Total number of records matching the query. Use this with skip and take to calculate pages.

Manual Pagination

// Fetch page 1 (first 20 records)
const page1 = await client.bookings.list({
  organisation: 'org-id',
  skip: 0,
  take: 20,
});

console.log(page1.data);        // Array of bookings
console.log(page1.meta.count);   // Total count, e.g. 154

// Fetch page 2
const page2 = await client.bookings.list({
  organisation: 'org-id',
  skip: 20,
  take: 20,
});

listAll()

Auto-Pagination

Most resources provide a listAll() method that returns an AsyncIterable. This automatically fetches pages in the background as you iterate, so you never have to manage skip and take manually.

The iterator fetches 25 records per page internally and yields them one at a time.

Auto-Pagination with for await

// Iterate one by one
for await (const booking of client.bookings.listAll({
  organisation: 'org-id',
})) {
  console.log(booking.id, booking.customer_name);
}

toArray()

Collecting All Results

If you need all records in memory at once, use the toArray() helper to collect the full AsyncIterable into an array.

  • Name
    toArray(iterable)
    Type
    function
    Description

    Accepts any AsyncIterable and returns a Promise resolving to an array of all items.

Collecting All Results

import { FellohClient, toArray } from '@felloh-org/node-sdk';

const client = new FellohClient({
  publicKey: 'your-public-key',
  privateKey: 'your-private-key',
});

const allBookings = await toArray(
  client.bookings.listAll({ organisation: 'org-id' })
);

console.log(`Total: ${allBookings.length} bookings`);