Matching items with assets

Hi again,
I created a vehicleImage content-type where a certain vehicleId (string) is bound to the corresponding category (string) and an image
I’m wondering whether there is a possibility to directly get the assets bound to the items;
I tried with a

content_type=vehicleImage&fields.category[in]=suv,elettrico&include=10&locale=en-US&fields.vehicleId[in]=xevMezzo,tonale,xevIntero,fallback&select=fields.vehicleId,fields.category,fields.img

where I query the content-type, all the possible categories (for a requirement I speak about on another post), and I select fields.vehicleId fields.category and fields.img in order to cleanup the response.
The reponse is something like

"items": [
    {
      "fields": {
        "vehicleId": "tonale",
        "category": [
          "suv"
        ],
        "img": {
          "sys": {
            "type": "Link",
            "linkType": "Asset",
            "id": "271rvrEVMqesWRCDWbnCRZ"
          }
        }
      },
...
],
"includes": {
    "Asset": [
      {
        "metadata": {
          ..
        },
        "sys": {
          "id": "1ltJsQxq3RDddF9S4yCJIr",
          ...
          },
        ...
        },
        "fields": {
          "title": "xev",
          "file": {
            "url": "//images.ctfassets.net/kgvyn12n9qwu/1ltJsQxq3RDddF9S4yCJIr/ee030f7ab97e4323228bbe8bf3d83c23/offer1.png",
            "details": {
              "size": 133297,
              "image": {
                "width": 410,
                "height": 374
              }
            },
            "fileName": "offer1.png",
            "contentType": "image/png"
          }
        }
      },
      ...
]

My question is: do I always have to match items[n]fields.img.id to includes[m].sys.id in order to retrieve the linked file URL (since the arrays are sorted differently) or is there a different, quicker way to do it?
Thanks in advance!

Unfortunately, this is a requirement when using vanilla REST calls; however, most of the client libraries should resolve these objects for you. E.g. the JavaScript client library resolves asset/entries on reference fields onto the reference field itself, which itself leverages this library.

1 Like

Thanks for the feedback! :slight_smile:

1 Like