Search code examples
contentful

Contentful CMS is not showing data properly


I am using Contentful CMS (community edition) with Next.js but Contentful Client keeps on vanishing the random data in response. Every time I need to change the status of entry to Unpublish and then again publishing it solves the issue. This is too disturbing because it prohibits the site to show data. Also, it's very hard to update entries and all linked data. Is anybody facing the same or have any solution?

export async function fetchEntries() {
  // const response = await client.getContentType("page");
  const entries = await client.getEntries();
  if (entries.items) return entries.items;
}

export async function getStaticProps() {
  const entries = await fetchEntries();
  let data = entries.filter((item) => item.sys.contentType.sys.id === "page" && item.fields.slug === "home");
  return {
    props: {
      data: data.length ? data[0] : null,
    },
  };
}

Contentful data is missing fields only sys object is shown You can have a look here


Solution

  • For someone in the future who encounters the same, here is the solution just add include property to your method where you are fetching the entries Read more here include resolves this package behind the scenes. Package is here contentful-resolve-response

    const entry = await client.getEntries(
      { 
        content_type: "page",
        "fields.slug": "home",
        include: 10 
      }
    );