Saturday 14 May 2016

2 out-of-the-box repository REST APIs you must keep handy while working with content in Alfresco

As an Alfresco developer, you should always know some of the basic things about content, such as - How to view a content? How to download a content? How to list down all the content from a folder and so on. In Alfresco, you have out-of-the-box repository web scripts available which takes care of all of the above. You must keep yourself familiar with these web scripts.

Let's take a look at 2 very useful content related repository web scripts (which basically are useful for 4 things). In my opinion, you must keep these 2 web scripts handy with you while working on any alfresco implementation. I have used Alfresco 5.1 Community Edition here.

1. View Content

In order to view a content, you should make a GET request to the following URL.

http://localhost:8080/alfresco/service/api/node/content/workspace/SpacesStore/18d2fa04-70ba-4865-afe6-e097b75f0576
Note:You must replace server, port and nodeid in the above URL as per your implementation.

When you hit the above URL, it will display the content in your browser. You may use it for previewing the content.

You can take a look at the description document of this web script at the following URL and can also try out the different URL options supported for viewing a content as mentioned there.
http://localhost:8080/alfresco/service/description/org/alfresco/content/content.get

2. Download Content

To download a content, you will be using the same web script we used above however only additional option that you will provide is a querystring parameter a=true

http://localhost:8080/alfresco/service/api/node/content/workspace/SpacesStore/18d2fa04-70ba-4865-afe6-e097b75f0576?a=true

When you hit the above URL, it will download the content.

3. Get list of contents from a specific folder

To  get a list of all the contents of a folder, you can hit the following web script.

http://localhost:8080/alfresco/service/slingshot/doclib/doclist/documents/node/workspace/SpacesStore/e0856836-ed5e-4eee-b8e5-bd7e8fb9384c

As highlighted in above URL, when you specify documents, it fetches all the documents for a given folder.

Description document for this web script can be found at
http://localhost:8080/alfresco/service/script/org/alfresco/slingshot/documentlibrary/doclist.get

3. Get list of  the contents & folders from a specific folder

To get a list of both contents & folders from a specific folder, you can hit the following web script. It is basically the same web script we used in #3. Only difference is, instead of specifying documents we will specify all there. If you specify anything except documents then it will list down both content & folders.

http://localhost:8080/alfresco/service/slingshot/doclib/doclist/all/node/workspace/SpacesStore/e0856836-ed5e-4eee-b8e5-bd7e8fb9384c
OR
http://localhost:8080/alfresco/service/slingshot/doclib/doclist/both/node/workspace/SpacesStore/e0856836-ed5e-4eee-b8e5-bd7e8fb9384c

One important thing to take a note over here is that both the above web scripts have lifecycle mentioned as internal. Hence, they are for alfresco internal use only and there may be the chances that it may get changed in future versions of alfresco. Hence, if you want to use them for integration purpose in your project then you must keep this point in consideration before using them. However, from a developer perspective it is a must to know about these web scripts available in Alfresco so as it will be helpful to you while working on any content related issue.

Hope this will be useful to you.

1 comment:

  1. Aadit Majmudar18 May 2016 at 04:24

    Gr8.

    Useful when we are dealing with the third party applications' integration with Alfresco.

    ReplyDelete