How to populate 1:n relation in component

I’ve got this sort of content setup:

I’m trying to query this with the REST api, ideally I would actually just want to populate everything recursively, but since that doesn’t seem to be an option I’m trying to use populate to get all my fields.

My issue is, with both of those components I just can’t seem to populate the ‘Location’ fields, which is a 1:n relation to a Locations collection I have, here is how I’ve tried:


const query = qs.stringify({
    populate: {
        Tickets: {
            populate: "Prices"
        },
        LocationInfobox: {
            populate: {
                Items: {
                    populate: "Location"
                }
            }
        },
        AccessibleLocations: {
            populate: "Location",
        }
    },
}, {
    encodeValuesOnly: true,
});

export const infoDataQuery = selector({
    key: 'infoData',
    get: async ({get}) => {
        const response = await api.get('info-page?' + query);
        console.log(response)
        return response.data.data.attributes;
    },
});
System Information
  • Strapi Version: 4.0.0
  • Operating System:
  • Database:
  • Node Version:
  • NPM Version:
  • Yarn Version:

It just doesn’t return anything for the field, I’ve tried the plural form ‘Locations’ as well, and also lowercase ‘locations’, since that’s what the internal content manager API seems to return, but no success.

It seems like this is only the case for this 1:n relation from a component, because ‘Items’ seems to to populate just fine.

Any insight on what I’m doing wrong would be greatly appreciated, it’s really frustrating seeing the content-manager api return the values I need, for the backend but having no idea how to query them myself…

Ah, this seems to be the bug mentioned here

It works if I change to a full access API token, which is a problem though since I want to query the api from my Frontend

@Joo Check following thread with workaround: Strapi V4 populate Media and Dynamiczones from Components - #16 by sg-code

Unrelated but just as a reminder: if some fields are not being populated even if specified, check if you allowed that role to access that collection type.

e.g. if product has a category but you only allow the user to find product, it will not populate the field category in that product. You have to allow find for product and category for product to populate fully

2 Likes