10
{
id: 2,
attributes: {
title: ‘Test Title’,
body: ‘Test Body’,
date: null,
createdAt: ‘2021-11-30T20:52:09.206Z’,
updatedAt: ‘2021-11-30T20:57:26.724Z’,
publishedAt: ‘2021-11-30T20:57:26.720Z’
}
Muhammed Sahil
  • 101
  • 1
  • 1
  • 5
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jan 05 '22 at 14:45

5 Answers5

18

I've had this struggle myself as well. And I couldn't get this working with their Query Engine & Entity Engine using Strapi 4 & Nuxtjs.

To show the images or (dynamic) components in the API, be sure to use:

http://localhost:1337/api/[your api]?populate=*

They are not shown by default unfortunately. They said:

We will not auto populate any field by default within Strapi as the purpose for not doing so is largely performance but also security as within the v4 if a role doesn’t have access to the find controller on a related content-type it is not possible to populate it.

Making this change on v4 is not possible as it would be considered breaking, but we are open to feature requests that extend past the default.

If you would wanna do this for Dynamic Zones with nested components you should do:

http://localhost:1337/api/[your api]?populate=ImagesRepeater.image

Here ImageRepeater is the name of the block and image is the field inside of the component.

If you want to achieve the same without populating this in the URL, you can find more of the docs here: https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest/populating-fields.html#population

BrianR.
  • 188
  • 7
3

Strapi 4 requires you to populate your request (see: population documentation )

which could look like this (for level 2 population):

    // populate request
    const qs = require('qs')
    const query = qs.stringify(
      {
        populate: {
          Title: {
            populate: ['Image']
          }
        }
      },
      {
        encodeValuesOnly: true
      }
    )
    // get id 
    const id = yourId
    // get rquest
    const Response= await axios.get(
      `http://localhost:1337/api/[your api]/${id }/?${query}`
    )
DontEatMyCookies
  • 188
  • 1
  • 12
1

As people have mentioned above, Strapi v4 requires you to populate your request for the REST API

The REST API by default does not populate any relations, media fields, components, or dynamic zones

You can create custom queries with QS library or if you just want response to be deeper than defult levels, Try Populate Deep plugin

Wahid Shaikh
  • 38
  • 1
  • 6
1

Add {?populate=*} at the end of url. Example, http://localhost:1337/api/cards?populate=*

  • 1
    While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Yunnosch Jul 13 '22 at 07:24
0

You can simply access the images in strapi V4+ by graphql query ===>

 images{
    data{
      id
      attributes{
        url
      }
    }
  }

image e.g ===>

enter image description here

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175