Pagination

    When you fetch a collection of resources, some endpoints might return you paginated results. If that's the case, the response will contain the total number of resources in the meta attribute:

    {
    "data": [...],
    "meta": {
    "total_count": 140
    }
    }

    You can change the default number of results returned on each page with the page[limit] query parameter, and get the next page of results with the page[offset] parameter:

    curl \
    -H 'Accept: application/json' \
    -H 'Authentication: Bearer <YOUR-API-TOKEN>' \
    https://site-api.datocms.com/site?page[limit]=50&page[offset]=100

    If you need to iterate over every resource in the collection, our Javascript client offers an async iteration statement with the listPagedIterator() method, which can automatically go through every page of results for you:

    import { buildClient } from '@datocms/cma-client-node';
    const client = buildClient({ apiToken: '<YOUR_TOKEN>' });
    for await (const article of client.items.listPagedIterator({ filter: { type: "article" }})) {
    console.log(article.title);
    }