Matt Freelance Web
Matt Freelance Web

Reputation: 97

how can i query deep image relation with strapi

i'm having a problem with querying strapi

i create a relation but i can't reach the image of it and i don't how to do it even after reading the docs

thanks for helping me

here is my query "localhost:1337/api/projects?populate=*"

my response is like this

{
  "data": [
    {
      "id": 1,
      "attributes": {
        "Title": "Booki",
        "Href": "https://www.matt3806.github.io/OC_webdev_P2/",
        "Description": "**Intégration d'une maquette** pour Booki, une startup fictive de manière **responsive** afin que le site puisse s'adapter à chaque taille d'écran",
        "createdAt": "2022-11-24T08:03:27.891Z",
        "updatedAt": "2022-11-24T08:35:02.452Z",
        "publishedAt": "2022-11-24T08:03:31.712Z",
        "Image": {
          "data": [
            {
              "id": 21,
              "attributes": {
                "name": "booki desktop (2).png",
                "alternativeText": "présentation sur ordinateur ",
                "caption": null,
                "width": 500,
                "height": 500,
                "formats": {
                  "thumbnail": {
                    "name": "thumbnail_booki desktop (2).png",
                    "hash": "thumbnail_booki_desktop_2_7205c44bca",
                    "ext": ".png",
                    "mime": "image/png",
                    "path": null,
                    "width": 156,
                    "height": 156,
                    "size": 18.48,
                    "url": "/uploads/thumbnail_booki_desktop_2_7205c44bca.png"
                  }
                },
                "hash": "booki_desktop_2_7205c44bca",
                "ext": ".png",
                "mime": "image/png",
                "size": 81.79,
                "url": "/uploads/booki_desktop_2_7205c44bca.png",
                "previewUrl": null,
                "provider": "local",
                "provider_metadata": null,
                "createdAt": "2022-11-24T08:02:04.171Z",
                "updatedAt": "2022-11-24T08:02:21.446Z"
              }
            }
          ]
        },
        "technos": {
          "data": [
            {
              "id": 1,
              "attributes": {
                "Name": "HTML5",
                "createdAt": "2022-11-23T09:18:58.933Z",
                "updatedAt": "2022-11-23T10:04:55.583Z",
                "publishedAt": "2022-11-23T09:19:04.765Z"
              }
            },
            {
              "id": 2,
              "attributes": {
                "Name": "CSS3",
                "createdAt": "2022-11-23T09:22:22.457Z",
                "updatedAt": "2022-11-23T10:03:29.101Z",
                "publishedAt": "2022-11-23T09:22:24.926Z"
              }
            }
          ]
        }
      }
    },

my technos normaly have an image but it doesn't appear

do you know how to do it specifying the query may be ?

Upvotes: 1

Views: 450

Answers (1)

antokhio
antokhio

Reputation: 2004

there is two options, easiest use strapi-plugin-populate and api/projects?populate=deep

The more advanced one is to use qs

const str = qs.stringify(
  {
    populate: { technos: { populate: ["media"] } }
  },
  { encodeValuesOnly: true }
);

Upvotes: 0

Related Questions