How can I filter assets to get only folders from adobe aem assets api | Community
Skip to main content
August 10, 2022
Solved

How can I filter assets to get only folders from adobe aem assets api

  • August 10, 2022
  • 1 reply
  • 1725 views

Hi Folks,

I am trying filter the content of adobe aem assets api to get only folders and skip files to check whether parent folder have any sub folder.

 

I am refereeing  below url for adobe aem documentation regarding asset api :
https://experienceleague.adobe.com/docs/experience-manager-64/assets/extending/mac-api-assets.html?lang=en

Can anyone help me to know how to filter the content of asset api.

 

Thanks,

Sandeep

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Nikhil_Verma

I think for what you're after, you need query builder instead of Assets API.

 

Try this: http://localhost:4502/bin/querybuilder.json?path=/content/dam&1_property=jcr:primaryType&1_property.value=sling:Folder

 

You should get a JSON output with a list of all folders inside DAM:

 

Folder structure in DAM:

1 reply

Nikhil_Verma
Level 4
August 12, 2022

I have the below folder structure in my AEM Assets containing a parent folder ('my-assets') which again contains 3 assets and 1 folder:

 

The Assets API on 'my-assets' folder returns below:

It is clear I see that for assets the 'properties' element has 'metadata' and dc:format' elements.

Whereas, for folders these elements don't exist.

Which makes sense, as dc:format and metadata nodes in CRX exists for assets and not folders.

So you can know whether it is a folder or an asset.

 

sandyT52Author
August 16, 2022

Thanks Nikhil for reply,

In my case metadata does not come, but i have done this using class field and it is working but to check this folders have sub-folders i am sending separate api calls for each folders and checking if it contains any folder or not which is time consuming, i need a way to send filter with request to check if it have folder or not
For file:

For folder :

 

 

Nikhil_Verma
Nikhil_VermaAccepted solution
Level 4
August 16, 2022

I think for what you're after, you need query builder instead of Assets API.

 

Try this: http://localhost:4502/bin/querybuilder.json?path=/content/dam&1_property=jcr:primaryType&1_property.value=sling:Folder

 

You should get a JSON output with a list of all folders inside DAM:

 

Folder structure in DAM: