Expand my Community achievements bar.

SOLVED

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

Avatar

Level 1

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.

 

sandyT52_0-1660111935785.png

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?l...

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

 

Thanks,

Sandeep

1 Accepted Solution

Avatar

Correct answer by
Level 5

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....

 

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

Screen Shot 2022-08-16 at 3.42.53 pm.png

 

Folder structure in DAM:

Screen Shot 2022-08-16 at 3.41.53 pm.png

View solution in original post

3 Replies

Avatar

Level 5

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

Screen Shot 2022-08-12 at 3.31.36 pm.png

 

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

Screen Shot 2022-08-12 at 3.26.03 pm.png

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.

 

Avatar

Level 1

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:

sandyT52_0-1660624686067.png

For folder :

sandyT52_0-1660632968903.png

 

 

Avatar

Correct answer by
Level 5

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....

 

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

Screen Shot 2022-08-16 at 3.42.53 pm.png

 

Folder structure in DAM:

Screen Shot 2022-08-16 at 3.41.53 pm.png