'Fetch API in DatoCMS doesn't bring all the published posts
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);
}
};
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Maxime Binet |