TenkaTenka
Sign in

Tenka Help Center › Developer area › Pagination and sync

Pagination and sync

Page by page, or only what changed since last time.

Two modes

Page by page

limit and offset: the classic mode, for screens and reports. Each resource's order is fixed and does not change between versions.

Only what changed (incremental)

desde (date or date-time) turns on incremental mode: only records created or changed since then, in change order. The response carries proximoDesde, proximoId and temMais; send the first two back as desde and depoisDe on the next call until temMais is false.

Pagination parameters

NameTypeDescription
limitintegerMax items (up to 200). Default 50.
offsetintegerOffset for pagination. Default 0.
desdestringOnly what changed from this instant (ISO-8601: 2026-08-27 or 2026-08-27T14:30:00). Turns on incremental mode: the response carries proximoDesde/proximoId/temMais to send back on the next call.
depoisDeintegerThe proximoId of the previous response, together with proximoDesde in desde. Breaks ties between records saved at the same instant.

The response envelope

NameTypeDescription
dataarrayThe records of the page.
moedastringAccount functional currency (ISO 4217) of the amounts.
limitintegerThe limit applied.
offsetintegerThe offset applied.
countintegerHow many records came in this page.
desdestringIncremental mode only: the cut applied.
temMaisbooleanThere is another page.
proximoDesdestringIncremental mode only: send back as desde on the next call.
proximoIdintegerIncremental mode only: send back as depoisDe on the next call.

The sync loop

Store proximoDesde and proximoId after each page and start from them on the next run. Records saved at the same instant are neither lost nor repeated, because the cursor is the date + id pair.

Python
import os
import requests

BASE = "https://tenka.app.br/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['TENKA_API_KEY']}"}
desde, depois_de = "2026-10-01", None  # the last saved checkpoint

while True:
    params = {"desde": desde, "limit": 200}
    if depois_de:
        params["depoisDe"] = depois_de
    page = requests.get(f"{BASE}/clientes", headers=HEADERS, params=params, timeout=30).json()
    if "erro" in page:
        raise RuntimeError(page["erro"])
    for record in page["data"]:
        save(record)
    if "proximoDesde" in page:
        desde, depois_de = page["proximoDesde"], page["proximoId"]
    if not page["temMais"]:
        break
save_checkpoint(desde, depois_de)