How to query the asset using a particular tag using graphql in aem | Community
Skip to main content
Level 3
December 3, 2024
Solved

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

  • December 3, 2024
  • 2 replies
  • 1228 views

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

 

kindly help on this



Best answer by AMANATH_ULLAH

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?


@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

2 replies

AMANATH_ULLAH
Community Advisor
Community Advisor
December 3, 2024

@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-api/sample-queries#sample-cities-named-variation

 

Amanath Ullah
VedhaSriAuthor
Level 3
December 3, 2024

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

 

AMANATH_ULLAH
Community Advisor
Community Advisor
December 3, 2024

@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
MukeshYadav_
Community Advisor
Community Advisor
December 3, 2024

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&property=jcr:content/metadata/cq:tags&property.value=we-retail:gender/men&property.operator=contains&p.limit=-1

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

Thanks