REST APIPagination
Pagination
How cursor-based pagination works in the Moviie REST API.
Pagination
Paginated endpoints use cursor-based pagination. Cursors are opaque tokens: you should never parse or construct them manually.
Query parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
cursor | string | — | Cursor from a previous response. Omit to get the first page. |
limit | number | 24 | Number of items per page (max varies per endpoint). |
Response format
{
"data": [ ... ],
"pageInfo": {
"nextCursor": "eyJpZCI6IjEyMyIsInNvcnRWYWx1ZSI6Ii4uLiJ9",
"hasMore": true
}
}| Field | Description |
|---|---|
data | Array of items for the current page. |
pageInfo.nextCursor | Pass as cursor to fetch the next page. null when there are no more pages. |
pageInfo.hasMore | true when there are more items to fetch. |
Iterating through all pages
async function fetchAllVideos() {
const videos = []
let cursor = undefined
do {
const url = new URL('https://api.moviie.ai/v1/videos')
url.searchParams.set('limit', '96')
if (cursor) url.searchParams.set('cursor', cursor)
const res = await fetch(url, {
headers: { Authorization: `Bearer ${process.env.MOVIIE_API_KEY}` },
})
const { data, pageInfo } = await res.json()
videos.push(...data)
cursor = pageInfo.nextCursor
} while (cursor)
return videos
}Common pitfalls
- Do not store cursors long-term. They are tied to a specific sort order and may become invalid if underlying data changes significantly.
- Always check
pageInfo.hasMorebefore fetching the next page:nextCursorisnullon the last page.