Image URL not showing on API Call Strapi v4 in single collection type

{
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’
}
1

5 Answers

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:

 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:

 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:

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( ` api]/${id }/?${query}` )

Add {?populate=*} at the end of url. Example, *

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

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

 images{ data{ id attributes{ url } } }

image e.g ===>

enter image description here

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like