Using the REST API to find elements inside a folder or a folder hierarchy

cancel
Showing results for 
Search instead for 
Did you mean: 

Using the REST API to find elements inside a folder or a folder hierarchy

angelborroy
Alfresco Employee
2 0 7,082

When using the Alfresco REST API, searching documents contained in a folder or in a folder hierarchy can be achived by some different ways.

You can examine these options in Structure, tags, categories and query documentation page.

If you are aware of the whole path for a parent folder, then you can use something similar to the following query to find every folder or document contained directly in this parent folder.

curl --location --request POST 'http://127.0.0.1:8080/alfresco/api/-default-/public/search/versions/1/search' \
--header 'Authorization: Basic YWRtaW46YWRtaW4=' \
--header 'Content-Type: application/json' \
--data-raw '{
   "query":{
      "query":"PATH:\"app:company_home/st:sites/cm:swsdp/cm:documentLibrary/*\" AND cm:name:\"Meet*\""
   }
}
'

If you want to perform the same search in all the folder hierarchy below the parent folder, you can use this one.

curl --location --request POST 'http://127.0.0.1:8080/alfresco/api/-default-/public/search/versions/1/search' \
--header 'Authorization: Basic YWRtaW46YWRtaW4=' \
--header 'Content-Type: application/json' \
--data-raw '{
   "query":{
      "query":"PATH:\"app:company_home/st:sites/cm:swsdp/cm:documentLibrary//*\" AND cm:name:\"Meet*\""
   }
}
'

Finally, if you code an application that is not aware of the path but only of the Node Id of the parent folder, you can try something like the following one.

curl --location --request POST 'http://127.0.0.1:8080/alfresco/api/-default-/public/search/versions/1/search' \
--header 'Authorization: Basic YWRtaW46YWRtaW4=' \
--header 'Content-Type: application/json' \
--data-raw '{
   "query":{
      "query":"ANCESTOR:\"workspace://SpacesStore/a211774d-ba6d-4a35-b97f-dacfaac7bde3\" AND cm:name:\"Meet*\""
   }
}'

>> There are many other ways to get nodes in a folder with the REST API. Have you any other to contribute?

 

About the Author
Angel Borroy is Hyland Developer Evangelist. Over the last 15 years, he has been working as a software architect on Java, BPM, document management and electronic signatures. He has been working with Alfresco during the last years to customize several implementations in large organizations and to provide add-ons to the Community based on Record Management and Electronic Signature. He writes (sometimes) on his personal blog http://angelborroy.wordpress.com. He is (proud) member of the Order of the Bee.