Lists on both APIs are paginated the same way:
pageandlimitin the query,dataandmetain the response. Search is the one exception. Previous: Errors | Next: Rate Limits
Reference - This guide is a tutorial. For exhaustive, always-current signatures and field lists, see the auto-generated reference:
SDK:
ContentsService,SearchServiceAPI: Storefront: Content
Prerequisites
A first request done (Quick Start)
Query parameters
curl "https://api.lynkow.com/storefront/a779c43c-430e-45d1-8749-2144d7f60a0f/contents?page=2&limit=10&locale=en"Parameter | Default | Maximum |
|---|---|---|
|
| |
|
|
|
Pages count from 1. A page past the last one returns an empty data array. Keep limit at 100 or below: depending on the list, a larger value returns 422 or is lowered to the maximum.
Two Storefront routes built to fetch a whole catalog in one call default to 500 items and accept up to 500: a category with its posts (/categories/{slug}, categories.getBySlug() in the SDK) and path resolution (/resolve).
The Admin API (/v1) uses the same parameters, defaults and maximum.
The meta object
{
"data": [ ... ],
"meta": {
"total": 42,
"perPage": 10,
"currentPage": 2,
"lastPage": 5,
"firstPage": 1,
"firstPageUrl": "/?page=1",
"lastPageUrl": "/?page=5",
"nextPageUrl": "/?page=3",
"previousPageUrl": "/?page=1"
}
}total: items matching the query, across all pages.perPage: the page size applied.currentPageandlastPage: where you are, and the last page number.lastPageis1when nothing matches.firstPage: always1.The
...Urlfields hold a query string only, without the endpoint path or your other parameters.nextPageUrlisnullon the last page. Build the next request fromcurrentPageinstead.
There is another page while currentPage < lastPage.
With the SDK
List methods take page and limit and return { data, meta }:
import { lynkow } from '@/lib/lynkow'
const { data, meta } = await lynkow.contents.list({ page: 2, limit: 10 })
const hasNext = meta.currentPage < meta.lastPageTo read a whole list, loop until the last page:
import type { ContentSummary } from 'lynkow'
import { lynkow } from '@/lib/lynkow'
export async function allPosts(): Promise<ContentSummary[]> {
const posts: ContentSummary[] = []
let page = 1
let lastPage = 1
do {
const { data, meta } = await lynkow.contents.list({ page, limit: 100 })
posts.push(...data)
lastPage = meta.lastPage
page++
} while (page <= lastPage)
return posts
}The SDK's PaginationMeta type also declares hasMorePages and hasPreviousPages. The API never sends them, so they are always undefined: compare currentPage with lastPage and with 1.
Search results
Search endpoints (/search and /search/{profileSlug}, search.search() in the SDK) return a different meta:
{
"data": [ ... ],
"meta": {
"total": 37,
"page": 1,
"totalPages": 4,
"perPage": 10,
"query": "pricing",
"processingTimeMs": 3,
"profile": "default"
}
}pageandtotalPagesreplacecurrentPageandlastPage.totalPagesis0when nothing matches.totalis an estimate.The default and maximum
limitcome from the search profile's settings.
const results = await lynkow.search.search('pricing', { page: 1, limit: 10 })
const hasNext = results.meta.page < results.meta.totalPagesInstant Search builds a search page on top of it.
Reference
Next Steps
Rate Limits - the limits a long loop can reach, and how to retry
Build a Blog with Next.js - a paginated blog list
Instant Search - search with pages and filters