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.
Asked
Active
Viewed 6,539 times
7
-
1Does this answer your question? [Components not included in Strapi api response](https://stackoverflow.com/questions/70249364/components-not-included-in-strapi-api-response) – IceJonas Dec 21 '21 at 17:38
3 Answers
28
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=*

Ammar Uppal
- 469
- 4
- 6
-
for me doesnt work, I get this : error: Invalid URI "/api/homes?populate=%2A" – Seb.code Jan 08 '22 at 14:35
-
2try this localhost:1337/api/homes?populate=* Do add the response you get if this doesn't work. – Ammar Uppal Jan 09 '22 at 15:08
-
this only works only the images are in same collection. what if the images in collection type and after we adding relation ? this is not working for that – Sanjula De Alwis Sep 09 '22 at 05:07
2
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,
- Data classification - In most cases, you don't need to return the entire payload such as when the collection is published and so forth.
- Performance - When you select only the necessary ones, your query to the DB will be more minor and therefore the result will come faster.
- Reduce payload - When you select only the necessary ones, you reduce the payload that returns to the client.

Avi Siboni
- 686
- 7
- 16
-2
at last write, populate=picture(name of media field)
-
As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 31 '22 at 12:07
-