Servlet to get all tags assigned to a DAM Asset in JSON format


Recently there was a requirement to fetch all tags assigned to a DAM Assets. It can be implemented via servlets where a Ajax call can be made. If you have never worked on such kind of use case then this is a must to learn and implement article for you. Its uses Tag Manager API and return data in JSON format. In our scenario it was easy to get data in JSON format, however you are free to convert it to any bases on your requirement

1. Define the annotaton @slingServlet with path you want to use for accessing it.

2.  Get the ‘path‘ parameter from request to get the image location. Once received, adapt this resource to Asset class. Start reading the ‘cq:tags‘ property where all tags are stored.

3. Now you have tags, but we need to get the title of tags and convert into JSON object that has to be returned.

4. At last, return the output in JSON format

5. The same request can be made via JS  to get the response

DAM Tags

Here is final complete code that can be used

Let me know if you need any help in implementation.

2 thoughts on “Servlet to get all tags assigned to a DAM Asset in JSON format

  1. Hi looking for help in implementing this.please give with full html and js file using will be really useful for beginners like us…


Leave a Reply

Your email address will not be published. Required fields are marked *