Querying vehicle image data

I can issue a query like that:

/vehicles/search?include=attributes,image

But that gives me an error:

/vehicles/search?include=attributes,image,image.files

(Error: “Included sub relation ‘files’ is invalid”)

According to the docs I should be able to query nested relationships with “dot” notation … ?
Or does that happen because at least one of the queried vehicles has no image?

If that is so, how can I get image data along with vehicle data with a single query if it is possible that vehicles have no images?

Hello

you cannot use the include for */search requests. Only for GET requests e.g. /vehicles/<ID>.

To get all data along the search you can use the following:

curl -X POST \
  'https://api.calponia.com/v2/vehicles/search' \
  --header 'Accept: */*' \
  --header 'Authorization: Token <TOKEN>' \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "query": {
        "project.id": { "_eq": "<PROJECT_ID>" }
    },
    "limit": 10,
    "offset": 0,
    "inlineData": true # This is the important line
}'

For best performance, always filter for the project or the vehicle id (otherwise the search can take some more time). Also include a sane limit.

It can be that there is no picture attached to the vehicle, then it will be null. See the API docs for the related search for more details:

Hm, but

/vehicles/search?include=attributes,image

works just fine, as I wrote …
The docs explicitly state: " You can pass an include query parameter to any endpoint (including POST/PATCH endpoints!) to include the relationships of the requested entities."

And unfortunately “InlineData”: true doesn’t resolve relations. An image contained in the vehicle data looks just like this:

		"image": {
			"_relType": "files",
			"id": "2e01c3c8-08e1-4d79-849a-91d67891ddff"
		},

So I assume I have to fetch the image (if one exists) with an extra query, e. g.

GET /files/2e01c3c8-08e1-4d79-849a-91d67891ddff

for above example?

The docs explicitly state: " You can pass an include query parameter to any endpoint (including POST/PATCH endpoints!) to include the relationships of the requested entities."

Oh sorry i must have missed it. You are totally right.

With this request:

curl -X POST \
  'https://api.calponia.com/v2/vehicles/search?include=image' \
  --header 'Accept: */*' \
  --header 'Authorization: Token <TOKEN>' \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "query": {
        "project.id": { "_eq": "<PROJECT_ID>" }
    },
    "limit": 10,
    "offset": 0,
    "inlineData": true
}'

you will get the relation in the “included” section of the response:

{
  "data": [ ... ],
  "meta": { ... },
  "included": {
    "image": [
      {
        "id": "64e051c5-7b19-44f2-81b7-d1fbf1a2c538",
        "project": {
          "_relType": "projects",
          "id": "cdc6114e-8b30-11ea-8349-dfd23c413e19"
        },
        "directory": {
          "_relType": "directories",
          "id": "cdf7671c-8b30-11ea-916c-0f31757c1433"
        },
        "path": "/vehicle-00000000-0000-4000-8000-000000000000-assets",
        "name": "profile-picture.jpg",
        "hash": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
        "size": 80134,
        "vehicle": null,
        "vehicleVersion": null,
        "device": null,
        "tasks": [],
        "createdBy": {
          "_relType": "users",
          "id": "0931238c-70ab-11e9-814a-23bfebb8d336"
        },
        "createdAt": "2020-04-30T22:20:32.330Z",
        "updatedAt": "2020-04-30T22:20:32.330Z",
        "_relType": "files"
      },
      ...

But your GET request will also work.

Ok, thanks :slight_smile:

I just saw that images can be included in html by something like:

https://download.calponia-latest.de/7e5c5a28-1d32-4ab5-9fbe-e8de6a90b678

so that I really only need the image id …

Ah yes, if you only want to display it and do not need the meta infos, the files id will directly resolve to the binary data when passed to the download endpoint.

The response headers there should also give you the file-name and file-type, if needed.