Search code examples
restherokustrapi

Heroku does not deliver media field


I set up strapi with heroku and created my first content (a blog post with title, description in rich text and cover image media file). When I make an API call like https://mybackend.....herokuapp.com/api/posts I receive title and description but the cover field with type=media is not being delivered. By the way, I'm new to backend development, so it's possible I'm completely missing something that may be completely obvious to those in the know.


Solution

  • Media are relations, and Strapi doesn't populate relations by default. (to ensure that if you have a biiiig content structure with tons of relations, we keep good performances)

    You will have to add ?populate=* to your request to fetch all the relations (first level)

    So: https://mybackend.....herokuapp.com/api/posts?populate=*

    This will give you your media in your API request.

    More information on the Strapi docs here: https://docs.strapi.io/dev-docs/api/rest/populate-select