Skip to main content

Overview

All list endpoints return paginated results using cursor-based pagination. This approach provides stable results even when new records are added between page fetches.

Query parameters

ParameterTypeDefaultDescription
limitinteger10Number of results per page. Min: 1, max: 100.
starting_afterstringA cursor for forward pagination. Pass the id of the last item from the previous page.
ending_beforestringA cursor for backward pagination. Pass the id of the first item from the previous page.

Response shape

Every list response includes pagination metadata:
{
  "object": "list",
  "data": [
    { "id": "pi_abc001", "object": "payment_intent", "amount": 1000, ... },
    { "id": "pi_abc002", "object": "payment_intent", "amount": 2500, ... },
    { "id": "pi_abc003", "object": "payment_intent", "amount": 500, ... }
  ],
  "has_more": true,
  "next_cursor": "pi_abc003"
}
FieldTypeDescription
objectstringAlways "list".
dataarrayThe page of results.
has_morebooleantrue if there are more results after this page.
next_cursorstring | nullThe ID to pass as starting_after for the next page. null when has_more is false.

Basic example

Fetch the first page of PaymentIntents with a limit of 3:
# First page
curl "https://api.leanrails.com/v1/payment_intents?limit=3" \
  -u "$API_KEY:"

# Next page using the cursor
curl "https://api.leanrails.com/v1/payment_intents?limit=3&starting_after=pi_abc003" \
  -u "$API_KEY:"

Iterating through all results

const fetch = require("node-fetch");

const API_KEY = process.env.API_KEY;
const credentials = Buffer.from(`${API_KEY}:`).toString("base64");

async function fetchAllPaymentIntents() {
  const allResults = [];
  let cursor = null;
  let hasMore = true;

  while (hasMore) {
    const url = new URL("https://api.leanrails.com/v1/payment_intents");
    url.searchParams.set("limit", "100");
    if (cursor) {
      url.searchParams.set("starting_after", cursor);
    }

    const response = await fetch(url.toString(), {
      headers: {
        Authorization: `Basic ${credentials}`,
      },
    });

    const page = await response.json();
    allResults.push(...page.data);

    hasMore = page.has_more;
    cursor = page.next_cursor;
  }

  return allResults;
}

const paymentIntents = await fetchAllPaymentIntents();
console.log(`Fetched ${paymentIntents.length} PaymentIntents`);

Backward pagination

Use ending_before to paginate in reverse. This returns items that come before the given cursor, in reverse chronological order.
curl "https://api.leanrails.com/v1/payment_intents?limit=10&ending_before=pi_abc001" \
  -u "$API_KEY:"
Do not combine starting_after and ending_before in the same request. The API will return a 400 error.

Tips

  • Use limit=100 when iterating through all results to minimize the number of API calls.
  • Results are always sorted by creation time in descending order (newest first).
  • Cursors are stable: adding or removing records does not shift the pagination window.