DatoCMS 中的 Fetch API 不会带来所有已发布的帖子

发布于 2025-01-14 18:31:22 字数 667 浏览 2 评论 0原文

我想从 DatoCMS 获取我所有已发布的博客文章。

事实上,我正在做这个。问题是,当我超过 100 时,它只带来 65...有人知道我做错了什么吗?谢谢

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);
  }
};

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);
  }
};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡淡の花香 2025-01-21 18:31:22

我不确定这个问题,但您是否尝试过计算记录数?只是为了检查是否有可能获得它们。
您还可以再次尝试跳过一些内容,以检查是否可以以某种方式获取所有文章。
更多信息请参见:https://www.datocms.com/docs/content-交付API/分页

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文