Expand my Community achievements bar.

AEM query builder api how to get publish url of image instead of image path?

Avatar

Level 5

When we query for a content fragment in query builder API, it returns the result as path of the image and not the actual image. In GraphQL query it returns the path however it is limited to functionalities and doesn't have sorting searching and ordering.

 

 
 
 
{
  "success": true,
  "results": 4,
  "total": 4,
  "more": false,
  "offset": 0,
  "hits": [
    {
      "featuredImage": "/content/dam/images/WELL_SITTING_EXERCISE_SEPT8_0.jpeg"
    },
    {
      "featuredImage": "/content/dam/images/WELL_SITTING_EXERCISE_SEPT8_0.jpeg"
    },
    {
      "featuredImage": "/content/dam/images/WELL_SITTING_EXERCISE_SEPT8_0.jpeg"
    },
    {}
  ]
}
Instead of getting image path I would like to get actual image URL. Would that be possible via queryBuilder API?
6 Replies

Avatar

Community Advisor

Using query builder API you will get only the jcr path. Could you please clarify the diff between path of the image vs actual image. You mean the nodeName of the asset in the JCR?

Avatar

Level 5

Actual Image meaning the `_authorUrl` or `_publishUrl` that I could use in frontend

Avatar

Community Advisor

@spidey1405 AEM Query builder API works on JCR level data, it only knows paths of the nodes with the mentioned predicates and doesnt know the final published URLs.. From what i get from you, you need fully qualified End url , which you can use it in your Front end to be used to display in your website..

Couple of things to note :-

  1. You should not expose Query Builder API publicly as it will allow anyone who has access to this API can bot your system.
  2. Query Builder only returns path, if you need URLs, write a wrapper service on top of this, which abstracts the Query Builder API, only returns what exactly needed for Front end and in desired format.

Avatar

Level 5

@Shashi_Mulugu I believe queryBuilder API would also need Bearer Auth when making call like GQL API. I tried making a public call and it returned 401 unauthorized. Note that my frontend is not going to query directly to AEM, my backend is connected to AEM.

 

Not just URLs in case of nested Content Fragment models, I need their details as well.

 

So for example lets say I have a content fragment model: Event like this:

 

title: TextField

Venue: TextField

Dates: Date (Where Date is a content fragment)

 

and here's how the model of Date looks like:

Day: Number

Month: Number

Year: Number

 

then when I query something like this, I need the results to contain all these data points and not the reference address of the Date model.

 

And regarding your second point:

  1. Query Builder only returns path, if you need URLs, write a wrapper service on top of this, which abstracts the Query Builder API, only returns what exactly needed for Front end and in desired format.

How can I do that? Any example or tutorial for the same?

Avatar

Community Advisor

The query builder API will give the results of events with path pointing to resource Date. In your code , you need to adapt that Date jcr path to resource and read the valueMap of that resource and return it to the front end. 

Regarding full qualified URL, you can use Externalizer API to get the fully qualified URL for an jcr path and return it as part response.

Ex: 

externalizer.externalLink(resourceResolver, Externalizer.PUBLISH, resourcePath)

Externalizer Doc: https://experienceleague.adobe.com/docs/experience-manager-64/developing/platform/externalizer.html?...  

Avatar

Level 5

@Saravanan_Dharmaraj I see... essentially what you're saying is that get the jcr:path and in order to fetch its content you need to make another api call right? Ideally I want to happen pagination/ sorting and searching within one single (either GQL or QueryBuilder call) to get all the data.