Expand my Community achievements bar.

How to query the asset using a particular tag using graphql in aem

Avatar

Level 3

Hi Team, I have a requirement how to query assets using a particular tag in AEM using GraphQL. I have even tried with chat GPT and Copilot but not getting required output some errors are coming. Below are the errors I am getting

VedhaSri_0-1733210141538.png

 

VedhaSri_0-1733209801767.png

kindly help on this



6 Replies

Avatar

Community Advisor

@VedhaSri 

To query content fragments based on tag

Use the GraphQl query in the below manner

query {
cityList(
includeVariations: true,
filter: {_tags: {_expressions: [{value: "tourism:city-break", _operator: CONTAINS}]}}
){
items {
name,
_tags
}
}
}

https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/headless/graphql...

 


Amanath Ullah

Avatar

Level 3

I want to query the assets like images present inside content/dam not the content fragment

 

Avatar

Community Advisor

@VedhaSri 

To query images present in DAM, you will have to prefer using Query builder API  or JCR SQL2 query instead of GraphQl


Amanath Ullah

Avatar

Level 3

But we are using graphql to send json response to UI team...so we have this requirement to fetch the list of images having a particular tag using graphql and send the response to UI.By any chance can we achieve this?

Avatar

Community Advisor

@VedhaSri 

There is no OOTB way of doing it

You will have to write custom implementation to convert response from query builder to graphql format


Amanath Ullah

Avatar

Community Advisor

Hi @VedhaSri ,

currently GraphQL is used for content fragment only, we use querybuilder.json to get the asset with a given tag like below

http://localhost:4502/bin/querybuilder.json?path=/content/dam/we-retail/en/people&type=dam:Asset&pro...

However if /bin/querybuilder.json is blocked from end user for security concern we can write same query in servlet

Thanks