Missing data from population of relational field

System Information
  • Next.JS:
  • Strapi 4.1.1:
  • macOS Monterey:
  • sqlite3:
  • Node 14.x.x:
  • Yarn 1.23.0:

For my portfolio I am calling data from my API related to specific projects of mine whose pages are dynamically generated with Next.js. Anyway, I make the call to the API but am missing deeper information that I can’t seem to extract.

export const getServerSideProps = async (context) => {
	const pid = context.query.pid;
	const url = process.env.STRAPI_API_URL;

	const query = qs.stringify(
		{
			populate: '*',
		},
		{
			encodeValuesOnly: true,
		}
	);
	const res = await axios.get(`${url}/projects/${pid}?${query}`);

	const projectData = res.data.data;

	return { props: { projectData, url } };
};

This returns:

‘samples’ is fully populated but ‘technologies’, which is a relational content type, is missing an ‘icon’ field (which is a media type) that I cannot seem to populate.

I’ve tried every request configuration listed here but nothing seems to work.

Maybe someone has an idea? Even a separate query like ‘http://localhost:1337/api/projects/1?populate[technologies][fields][0]=icon’ returns a 500 error.

Hi there, you’ll need to populate at each level of query, here is an example I was using that populates multiple levels etc.

Docs: Entity Service API - Populating - Strapi Developer Docs

    let featuredRetreats = await strapi.entityService.findMany(
      "api::featured-retreat.featured-retreat",
      {
        fields: ["ordinal", "feature_type", "width"],
        populate: {
          retreat: {
            fields: ["title"],
            populate: ["lead_image"],
            populate: {
              tags: { fields: ["tag"] },
              room_types: { fields: ["price", "start_date"] },
              lead_image: {
                fields: ["alternativeText", "width", "height", "formats"],
              },
            },
          },
        },
        sort: ["feature_type", "ordinal"],
      }
    );