DevelopersBuild safely

Pagination and rate limits

Page through v1 lists with limit and next_cursor, walk them with the SDK, and stay inside the request limits.

2 min read

Every v1 list returns one page at a time. Every request counts toward a few rate limits; when you go over one, Fianto answers 429 and tells you how long to wait.

Pagination

A list answers with items and next_cursor:

{ "items": [ … ], "next_cursor": … }
ParameterRules
limit1 to 100. Default 20
cursorThe next_cursor of the previous page. Leave it out for the first page
  • Orders, payments, subscriptions, products and prices use numeric cursors. A full last page still returns a cursor, and the page after it is empty. Stop on an empty page, or on null.
  • Events use evt_… ids as cursors, and return next_cursor: null when there are no more.
curl "https://api.fianto.xyz/v1/orders?limit=50" \
  --user "$FIANTO_APP_ID:$FIANTO_APP_SECRET"

# the next page
curl "https://api.fianto.xyz/v1/orders?limit=50&cursor=NEXT_CURSOR" \
  --user "$FIANTO_APP_ID:$FIANTO_APP_SECRET"

In the SDK

A list() call returns a PagePromise. await it for one page, or for await it to walk every item. The SDK fetches the next page only as you read, and stops on next_cursor: null or an empty page.

import { Fianto } from '@fianto/sdk';

const fianto = new Fianto();

// One page.
const page = await fianto.payments.list({ limit: 50 });
console.log(page.items.length, page.next_cursor);

// Every item, page by page.
for await (const payment of fianto.payments.list({ limit: 100 })) {
  console.log(payment.id, payment.status);
}

Rate limits

LimitScope
300 requests per minutePer IP address
120 writes and 600 reads per minutePer application
300 writes per minutePer merchant, across all its applications
10 test events per hourPer application, shared with the dashboard's test button

Over a limit, Fianto answers 429 with a Retry-After header and the code rate_limited: wait that many seconds, then retry.

The SDK retries a 429 on its own, waiting for Retry-After. When it gives up, after its retries or at once when Retry-After asks for more than 10 seconds, it throws a RateLimitError with the wait in retryAfterSeconds:

import { Fianto, RateLimitError } from '@fianto/sdk';

const fianto = new Fianto();

export async function recentOrders() {
  try {
    return await fianto.orders.list({ limit: 20 });
  } catch (err) {
    if (err instanceof RateLimitError) {
      console.warn(`Rate limited; retry in ${err.retryAfterSeconds ?? 'a few'} seconds`);
    }
    throw err;
  }
}

See also

Was this page helpful? Tell us

On this page