REST API populate with pagination

Hello!

I have categories endpoint and they’re linked with articles. On our homepage I want to show the last 10 articles from each category.
However, I cannot get the pagination to work with populate.

Here’s the endpoint
localhost:1337/api/categories?populate[articles][populate][image]=%2A&populate[articles][fields][0]=title&populate[articles][fields][1]=description&populate[articles][pagination][pageSize]=1&populate[articles][sort][0]=createdAt%3Adesc&populate[svg][populate]=%2A&filters[site][id]=1

I’m also attaching the code (might be easier to understand). It’s parsed with qs.stringify qs.stringify(urlParamsObject, { encodeValuesOnly: true })

    fetchAPI("/categories", {
      populate: {
        articles: {
          populate: {
            image: "*",
          },
          fields: ["title", "description"],
          pagination: {
            pageSize: 1,
          },
          sort: ["createdAt:desc"],
        },
        svg: {
          populate: "*",
        },
      },
      filters: {
        site: {
          id: siteId,
        },
      },
    }),

Does anyone know where the problem is?

Thank you very much!

Were you able to get this working? I am wondering the same thing

AFAIK this is not supported - the API always returns all related entities.

Maybe you could work around this using multiple requests where you first fetch all your Categories and then you fetch 10 articles for each. Roughly like this:

const categories = await request("/api/categories?pagination[pageSize]=999")

const articlesPerCategory = Promise.all(categories.map(category => {
  return request(`/api/articles?filters[category]=${category.id}?pagination[pageSize]=10`)
}))

Not the most performant solution tough. ./