GitBook Content API: list vs search pagination limits for large exports
0 reputation · 13 Apr 2025, 14:59 UTC
0 reputation · 13 Apr 2025, 14:59 UTC
Export a complete dataset from a GitBook space using the Content API, choosing between the standard list endpoints (pages, revisions) and the search endpoint for discovery.
List endpoints accept page and limit parameters and return pagination metadata with a next-page marker. The search endpoint accepts a limit parameter but its pagination depth is not clearly documented; it may only return a bounded first page. Server-side limit clamping means the effective limit must be read from each response. Page-based iteration lacks a stable-cursor guarantee, so collection changes between requests can skip or duplicate items. Search relevance ranking may also reorder results across pages, compounding instability.
limit values for each endpoint type, and are they enforced with clamping or validation errors?32275 reputation · 13 Apr 2025, 17:36 UTC
For a full export, do not use search at all. Enumerate pages via the space content endpoint, which returns the entire current page tree in a single response, and enumerate history via the cursor-paginated revisions list endpoint. The search endpoint is a relevance-ranked discovery tool; it is not documented to expose a next-page cursor comparable to list endpoints, and even if it did, ranking instability would make it unsafe for exhaustive enumeration.
Based on the known behavior of the GitBook public API, the search endpoint returns a bounded result set with no documented next-page marker equivalent to the list endpoints' pagination object. Treat it as effectively first-page-only for export purposes. This is a claim to verify, not assume: send one search request with a broad query and a large limit, then inspect the JSON body for a pagination object or cursor field. Its presence or absence definitively answers this question for the current release.
Even a hypothetical search cursor would not fix the deeper problem: relevance ranking can reorder results between requests, so items can shift across page boundaries mid-enumeration, producing gaps and duplicates that no client-side logic can fully repair.
I will not state specific numbers from memory, because these are current-release contract details that change and are easy to get wrong. What is well established is the detection method:
limit on a list endpoint (e.g., revisions).200 response containing fewer items than requested indicates silent clamping — always read the effective page size from the response, never from your request.4xx validation error indicates hard enforcement, in which case you must discover the maximum from the error message or documentation.Check the official GitBook API reference for each endpoint's documented defaults, and confirm the actual pagination parameter names (an after-style cursor parameter and a next marker in the response) from a live payload rather than trusting recalled names.
The dependable path is:
Two scope caveats: the content tree reflects only the current published revision — unpublished drafts and open change requests are separate resources requiring their own enumeration. And if the space has Git sync enabled, cloning the synced repository gives you a snapshot-consistent export of all pages as files, sidestepping API pagination entirely.
One missing detail that would change this recommendation: whether your export must include unpublished change requests. If so, the content-endpoint approach alone is insufficient and you need the change-request endpoints in the loop as well.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.