Customize rest api response levels (object vs id)

Rest api returns only 2 levels of collections. After 2 levels only the ids of the collection are returned. What is the simplest way to modify the levels returned without using graphql?

Being able to specify either ids or the entire relation object would be great.
e.g. The /user/ route and the /auth/local route both reference the User.setting.json model. But only the /user/ route references the User controller.

I now see how to populate only specific relations including child relations. Very cool!

strapi.query('restaurant').find({ id: 1 }, ['category', ''])

Wonder if it would be worth moving this functionality into the model so we don’t have to modify the controllers. Something like this:

"example": {
   "model": "example",
   "populate_relation": [ "category", "" ]
1 Like

Please do feel free to make a feature request on that last part, on GitHub. In the mean time I’ll ping @Jab, @sam-pires, and @Aurelsicoko :wink:

1 Like

We use to have a setting autoPopulate which enables the population of every relational field by default. It might worth it to remove it and replace it with a more precise setting such as populate which could accept multiple values.

  • populate: all would have the same behavior as the autoPopulate by populating the first level of relational fields.

  • populate: ['category', 'category.tags'] would only populate the category field at the first level and the tags relational field at the second level.

  • populate: ['category', ''] would only populate the category field at the first level, and the tags relational field at the second level by only returning the name of it.

IMO, it’s very close to an advanced query system that we could implement in the REST API. I don’t know what we have in mind regarding this and the v4 (cc @alexandrebodin)

1 Like

When you say, you used to have a setting, does that mean it is no longer available?

It has changed in the stable, but in v4 we have an entirely new population system coming that will give a lot of freedom and will be implemented in a very easy way.

Cool – it looks like I could graphQL for now – I am trying to get a more full structure for passing by our VueJS front end – so it doesn’t need to make additional requests to get more data.

Hello @DMehaffy so have you a deadline date to the release of the feature ?

The v4? we have tentative dates:

Beta will likely be sometime late Q3, first “stable” release will be early Q4 to late Q4. It largely depends on how quickly we can make the changes. There are about 4 projects being worked on in parallel for the v4 but database layer changes won’t start until early Q3.

Hey, how to use it on repeatable components and dynamic zone?

I have v4 installed right now, but relation fields are not being returned. Also, cannot find any docs to the “entirely new population system”. Any help would be appreciated. I’m not using GraphQL and would like to use relation fields if they are returned in API queries.

Current docs are here: REST API - Strapi Developer Docs

we are currently working on a documentation PR that adds far more examples on how to populate:

You can view this documentation using the following temporary link:

Thanks for the reply. Took a glance. Seems good. Was able to figure out a lot on my own, but instructions never hurt.