Using CMIS Browser protocol

CMIS (Content Management Interoperability Services) is an Oasis Standard to work with one or more Content Management repositories.

The API is exposed using three different bindings for clients:

Additionally, several client libraries are provided in Apache Chemistry web page, like Java, Python, PHP, .NET, Objective-C and JavaScript.

In this blog post, RESTful Browser binding operations for an Alfresco CMIS Repository are described.

Base URL and Authentication

For Alfresco 4.2+, the base URL for CMIS Browser binding is:

http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser

It can be used HTTP Basic Auth to obtain repositories information using this base URL:

$ curl -X GET \
http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser \
     -H 'Authorization: Basic YWRtaW46YWRtaW4='
{
   "-default-":{
      "repositoryId":"-default-",
      "repositoryName":"",
      "repositoryDescription":"",
      "vendorName":"Alfresco",
      "productName":"Alfresco Enterprise",
      "productVersion":"6.1.0 (3 r0f0034ee-b79)",
      "rootFolderId":"b1ee4176-6712-468c-89b0-dd0352e93450",
      "latestChangeLogToken":null,
      "cmisVersionSupported":"1.1",
      …
   }
}

Navigation

Repository can be browsed by using Folder and Document names in the URL. For instance, to have access to “Shared” folder in Repository root, it can be used following sentence:

$ curl -X GET \
http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser/root/Shared \
-H 'Authorization: Basic YWRtaW46YWRtaW4='
{
   "objects":[
      {
         "object":{
            "properties":{
               "cmis:name":{
                  "value":"New Folder"
                  }
            }
         }
      },
      {
         "object":{
            "properties":{
               "cmis:name":{
                  "value":"Sample-Document.docx"
               }
            }
         }
      },
      {
         "object":{
            "properties":{
               "cmis:name":{
                  "value":"test.txt"
                  }
            }
         }
      }
   ],
   "hasMoreItems":false,
   "numItems":3
}

Children list is returned as result, as this is the default Children Object for a Folder Object. If we were accessing to a different type of object, following elements are returned as result:

cmis:document        content
cmis:folder          children
cmis:relationship    object
cmis:policy          object
cmis:item            object

Objects

When accessing an object, different detail can be specified by using cmisselector parameter in an HTTP GET request: children, parents, object, properties, content, renditions, version, relationships, policies, acl

Accessing to document properties, can be expressed with the following URL:

$ curl -X GET \
'http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser/root/Shared/test.txt?cmisselector=properties' \
-H 'Authorization: Basic YWRtaW46YWRtaW4=' \

Actions

In order to perform operations in a Repository node, cmisaction parameter in an HTTP POST request must be used: createDocument, createFolder, createRelationship, createPolicy, createItem, query, createType, deleteType, delete, deleteTree, deleteContent, checkOut, checkIn, update

A new document of type cmis:document and name test.txt (uploading content from local file stored at /tmp/test.txt) can be created by using createDocument action.

$ curl -X POST \
http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser/root/Shared \
-H 'Authorization: Basic YWRtaW46YWRtaW4=' \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
-F cmisaction=createDocument \
-F 'propertyId[0]=cmis:objectTypeId' \
-F 'propertyValue[0]=cmis:document' \
-F 'propertyId[1]=cmis:name' \
-F 'propertyValue[1]=test.txt' \
-F file=@/tmp/test.txt

This document can be removed using delete action.

$ curl -X POST \
http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser/root/Shared/test.txt \
-H 'Authorization: Basic YWRtaW46YWRtaW4=' \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
-F cmisaction=delete

And even queries can be also launched by using the query action.

$ curl -X POST \
http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser \
-H 'Authorization: Basic YWRtaW46YWRtaW4=' \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
-F cmisaction=query \
-F 'statement=select * from cmis:document where cmis:name like '\''test.txt'\'''

It’s recommended to use in every HTTP request the param succinct=true to obtain a smaller payload.

Additional samples

Additional CMIS Browser REST API invocations are available at GitHub as a Postman Collection:

https://gist.github.com/aborroy/3f1f2360b0e85067675643aa648a8112

Published by angelborroy

Understanding software.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: