[IMPLEMENTED] Add url to Liquid asset

Hi Sebastian,

Currently the Asset Event enrichment looks like this:

{
    "id": "123...", // Id of the asset
    "actor": { "type": "subject", "id": "123..." }, // Id of the user
    "appId": { "name": "my-app", "id": "123..." }, // App name and id
    "created": "2018-01-01T12:00:00Z",
    "createdBy": "subject:123",
    "fileName": "Avatar.png",
    "fileSize:": 512000,
    "fileVersion": 1,
    "isImage": true,
    "lastModified": "2018-01-01T12:00:00Z",
    "lastModifiedBy": { "type": "subject", "id": "123..." },
    "mimeType": "image/png",
    "pixelHeight": 600,
    "pixelWidth": 800,
    "timestamp": "2018-01-01T12:00:00Z",
    "type": "Created", // The type of the event.
    "user": { // User information
        "id": "123...",
        "name": "John Doe",
        "email": "john@email.com"
    },
    "version": 1 // Version of the asset, increased with any operation
}

Link to docs: Rules | Squidex

Would it be possible to add url to this structure? It should look like this:

{
    "id": "123...", // Id of the asset
    "actor": { "type": "subject", "id": "123..." }, // Id of the user
    "appId": { "name": "my-app", "id": "123..." }, // App name and id
    "created": "2018-01-01T12:00:00Z",
    "createdBy": "subject:123",
    "url": "http://localhost:5000/api/assets/my-app/38d92943-4558-49cb-b1d0-b845c6b5e543/" // Add new url property here
    "fileName": "Avatar.png",
    "fileSize:": 512000,
    "fileVersion": 1,
    "isImage": true,
    "lastModified": "2018-01-01T12:00:00Z",
    "lastModifiedBy": { "type": "subject", "id": "123..." },
    "mimeType": "image/png",
    "pixelHeight": 600,
    "pixelWidth": 800,
    "timestamp": "2018-01-01T12:00:00Z",
    "type": "Created", // The type of the event.
    "user": { // User information
        "id": "123...",
        "name": "John Doe",
        "email": "john@email.com"
    },
    "version": 1 // Version of the asset, increased with any operation
}

The url should look exactly like it does when you run the following GraphQL query (http://localhost:5000/api/assets/my-app/38d92943-4558-49cb-b1d0-b845c6b5e543/):

{
  findAsset(id: "38d92943-4558-49cb-b1d0-b845c6b5e543") {
    url
  }
}
{
  "data": {
    "findAsset": {
      "url": "http://localhost:5000/api/assets/my-app/38d92943-4558-49cb-b1d0-b845c6b5e543/"
    }
  },
  "extensions": {
    "tracing": {
      "version": 1,
      "startTime": "2024-04-09T16:20:04.00942Z",
      "endTime": "2024-04-09T16:20:04.0109231Z",
      "duration": 1503100,
      "parsing": {
        "startOffset": 1000,
        "duration": 17700
      },
      "validation": {
        "startOffset": 20000,
        "duration": 222100
      },
      "execution": {
        "resolvers": []
      }
    }
  }
}

Then I can use it like this in my Liquid syntax:

// Input

{% for id in event.data.assets.iv %}
   {% asset 'ref', id %}
   Text: {{ ref.fileName }} {{ ref.id }} {{ ref.url }}
{% endfor %}

// Output

Text: Asset1_FileName Asset1_ID http://localhost:5000/api/assets/my-app/38d92943-4558-49cb-b1d0-b845c6b5e543/
Text: Asset2_FileName Asset2_ID http://localhost:5000/api/assets/my-app/55d92943-4558-49cb-b1d0-b845c6b5e599/

Please let me know if the spec is not clear enough.

Thanks!

There is a filter that works directly on the event or ID.

{{ event | assetContentUrl }}
or
{{ id | assetContentUrl }}

I’m not sure I follow.

Can you please put it in the following context?

I have the following Liquid:

{    
    {% for brandId in event.data.brand.iv %}
        {% reference 'brand', brandId %}
        "brand": "{{brand.data.name.iv}}"
    {% endfor %}
    "model": "{{event.data.model.iv}}",
    "slug": "{{event.data.slug.en-US}}",
    [[ Put image Liquid here. The name of my image property is called image ]]
}

Something like this:

{{ event.data.image.iv[0] | assetContentUrl }}

The left side must be an asset ID.

Hi Sebastian,

I’ve tried both:

`"justTesting": "{{event.data.image.iv[0].id | assetContentUrl}}",`

and

`"justTesting": "{{event.data.image.iv[0] | assetContentUrl}}",`

but none work. Got any clues?

BTW, I’m using https://cloud.squidex.io/ in case you’re wondering about Squidex version that I’m using.

Thanks.

Hi Sebastian, did you have some time over to have a look at this one? :slight_smile:

Yes, it is implemented, but not deployed yet.

Nice! Let me know when it’s deployed and I’ll test it right away.

Either tomorrow evening or Friday.

1 Like

it is deployed now. Sorry for the delay

Thank you. No problem!

What is the syntax? Can you give me an example?

Exactly the one above should work.

Thank you, Sebastian :smiling_face_with_three_hearts:

I can confirm now that this is indeed working.

This is the proper syntax for anyone who is interested:

"justTesting": "{{event.data.image.iv[0] | assetContentUrl}}",

2 Likes