Quickstart

Quickstart: paginate through list results with a cursor

Credicorp list endpoints use cursor pagination: follow next_cursor until it is null. Cursor paging is stable under inserts, so you never skip or double-count a row the way offset paging can. This recipe drains a list endpoint completely in a simple loop.

2 min read

next_cursorFollow until null
limitPage size (capped)
stableSafe under inserts

The pagination loop

def fetch_all(path):
    items, cursor = [], None
    while True:
        params = {'limit': 100}
        if cursor:
            params['cursor'] = cursor
        body = requests.get(f'{BASE}/{path}', params=params, timeout=10).json()
        items.extend(body['data'])
        cursor = body.get('next_cursor')
        if not cursor:
            return items

Pass the returned next_cursor back as the cursor parameter on the next request. When the response has no next_cursor (or it is null), you have reached the end.

Why cursors, not offsets

Offset paging (?page=3) breaks when rows are inserted between requests — you re-see or skip items. A cursor points at a stable position in the result set, so paging stays correct even as data changes underneath you.

Frequently asked questions

What page size should I use?

Request the largest limit the endpoint allows to minimise round-trips; the API caps it, so an over-large value is simply clamped.

Can I jump to page N?

No — cursors are sequential by design. If you need random access, fetch and index the full set once, then page in memory.

Funding for UK limited companies

Credicorp lends to your company, not to you personally — short-term working capital with no personal guarantee. See what your business could access.