Minh Mít
Minh Mít

Reputation: 127

Get All Folder and Documents in Repository Alfresco Restful

I'm learning Alfresco. I want get all folder and documents in Repository with Restful API. How can I do this?

Upvotes: 2

Views: 7873

Answers (3)

Hari
Hari

Reputation: 103

List of documents and folders can be obtained using below endpoints.

GET /alfresco/service/slingshot/doclib/doclist/{type}/site/{site}/{container}

        type = documents or folders
        container = documentLibrary

Reference :

Browser available Webscripts here:

http://server:port/alfresco/service/index/all

Document List Webscript

http://server:port/alfresco/service/script/org/alfresco/slingshot/documentlibrary/doclist.get

Alfresco Version : Community v5.0.0

Upvotes: 1

Thomas
Thomas

Reputation: 1312

Webscripts are a nice way to build your own API but in this case you should be fine with the buildin API that Alfresco provides you OOTB.

You can fetch all folders/documents using the REST APIs getDescendants call. Please see the API spec for the exact details:

https://wiki.alfresco.com/wiki/Repository_RESTful_API_Reference#Retrieve_tree_of_descendants_.28getDescendants.29

It returns a list of descendant objects of the specified folder for the defined number of levels in the tree.

GET /alfresco/service/api/node/{store_type}/{store_id}/{id}/descendants?types={types}&filter={filter?}&depth={depth?}

It starts at the folder identified with the ID param and applies the optional arguments to your call. This means that you can e.g. filter by type (document, folder,etc) and define a depth to query. Using -1 returns you all levels.

Upvotes: 2

Krutik Jayswal
Krutik Jayswal

Reputation: 3175

We can create restfull services using webscript of alfresco.For understanding webscript you can follow below link.

https://wiki.alfresco.com/wiki/Web_Scripts

For creating webscript for listing folders below are the file which you will need to create.

1.list-folders.get.desc.xml

<webscript>
  <shortname>Folder Listing Utility</shortname>
  <description>Java-backed implementation of listing folder contents
  </description>
  <url>/javadir/{folderpath}?verbose={verbose?}</url>
  <authentication>user</authentication>
</webscript>

2.list-folders.get.html.ftl

<html>
 <head>
  <title>Folder ${folder.displayPath}/${folder.name}</title>
  </head>
 <body>
   <p>Alfresco ${server.edition} Edition v${server.version} : dir</p>
  <p>Contents of folder ${folder.displayPath}/${folder.name}</p>
  <table>
   <#list folder.children as child>
   <tr>
   <td><#if child.isContainer>d</#if></td>
   <#if verbose>
     <td>${child.properties.modifier}</td>
     <td><#if child.isDocument>
       ${child.properties.content.size}</#if></td>
     <td>${child.properties.modified?date}</td>
   </#if>
   <td>${child.name}</td>
   </tr>
   </#list>
  </table>
 </body>
</html>

The web script description specifies a URI template containing the tokens {folderpath} and {verbose?}. The folderpath token represents the folder to list and the verbose URI argument specifies whether a verbose listing is required or not. The HTML response template renders the contents of the specified folder, taking into account the verbose flag. It does this by accessing the web script model values named folder and verbose.

You need to put above files inside below path.

Company Home > Data Dictionary > Web Scripts Extensions > org

Upvotes: 1

Related Questions