Fetch API in DatoCMS doesn't bring all the published posts

355 Views Asked by At

I want to fetch all my published blogposts from DatoCMS.

Actually, I'm doing this. The problem is that it only brings 65 when I have more than 100... does anyone know what I'm doing wrong? thanks

export default async (req: NextApiRequest, res: NextApiResponse) => {
  try {
    const response = await datoManagement.items.all(
      {
        // nested: true,
        filter: {
          type: 'blog_model' // you can use models `api_key`s or models IDs
        },
        page: {
          offset: 0,
          limit: 500
        }
      },
      {
        allPages: true
      }
    );
    console.log(response.length);
    res.status(200).send(response);
  } catch (error) {
    res.status(200).send('no ok');
    console.log(error);
  }
};
1

There are 1 best solutions below

0
On

I am not sure about the issue but did you try to count the number of records? Just to check if it seems possible to get them. You could also try some skip, again, to check if it is somehow possible to get all your articles. More infos here: https://www.datocms.com/docs/content-delivery-api/pagination