Reputation: 579
I have a media field in my collection of strapi (v4) server named Picture but it doesn't come up in api response when I request localhost:1337/api/products.
Upvotes: 12
Views: 9848
Reputation: 804
After reading Strapi Docs - here, turn out you can populate directly the media fields -
const qs = require('qs');
const query = qs.stringify({
populate: [
'seoData',
'seoData.sharedImage',
'seoData.sharedImage.media',
],
}, {
encodeValuesOnly: true,
});
await request(`/api/articles?${query}`);
instead of populating all(by *) which is not a good practice because,
Upvotes: 3
Reputation: 579
Solved, yay!
Documentation of Strapi v4 says:
Relations population
By default, relations are not populated when fetching entries.
Queries can accept a populate parameter to explicitly define which fields to populate, with the following syntax:
GET /api/books?populate=*
So I had to just postfix my GET request with ?populate=*
Answer: localhost:1337/api/products?populate=*
Upvotes: 34