REST API

Pagination

How to use page and size parameters in list APIs, and how to iterate through all data sequentially.

Onttle list endpoints (GET /tables/{table}) support offset-based pagination using page and size parameters.


Parameters

Parameter Type Default Allowed values Description
page number 1 Integer, 1 or greater Page number to retrieve (starting from 1)
size number 50 Integer from 1 to 100 Number of items to return at once

size accepts any integer from 1 to 100. A value outside that range or a non-number (for example 0, 500, abc) returns 400 invalidRequest. The most you can fetch in one request is 100 items.


The pagination Object in Responses

List responses include both list and pagination.

{
  "list": [ ... ],
  "pagination": {
    "page": 1,
    "size": 50,
    "total": 85,
    "totalPages": 2
  }
}
Field Type Description
page number Current page number
size number Items per page that was applied
total number Total number of matching items across all pages
totalPages number Total number of pages (total divided by size, rounded up)

Checking if Another Page Exists

function hasNextPage(pagination: {
  page: number
  size: number
  total: number
  totalPages: number
}): boolean {
  return pagination.page < pagination.totalPages
}

// Usage
const { list, pagination } = await res.json()

if (hasNextPage(pagination)) {
  // Fetch next page: page + 1
}

Fetching All Data Sequentially

When you need to retrieve all data, iterate through pages sequentially.

async function fetchAllContents(projectId: string): Promise<unknown[]> {
  const all: unknown[] = []
  let page = 1
  const size = 100

  while (true) {
    const res = await fetch(
      `https://api.onttle.com/v1/${projectId}/tables/posts?page=${page}&size=${size}`,
      {
        headers: {
          Authorization: `Bearer ${process.env.ONTTLE_API_KEY}`,
        },
      },
    )

    if (!res.ok) throw new Error(`HTTP ${res.status}`)

    const { list, pagination } = await res.json()
    all.push(...list)

    if (page >= pagination.totalPages) break
    page += 1
  }

  return all
}

When iterating through large datasets, set size to the maximum of 100 to reduce the number of API requests. If you send requests too quickly you may receive 429; wait for the time given in the Retry-After header as described in Error Codes, then retry.


Cautions When Iterating During Data Changes

With offset-based pagination, adding or removing items while iterating can cause the following issues.

  • Duplicate items: The last item from the previous page may appear again on the next page.
  • Missing items: Deleted items cause subsequent items to shift forward, resulting in skipped entries.

If you must iterate through all data in an environment with frequent changes, keep sorting conditions consistent and, if possible, run the iteration during a period with no data changes.


Next Steps

  • Response Format — Understand the structure of list and single-item responses in detail.
  • Request Examples — Learn how to combine page, size, fields, sort, filter, op, search, and language.