HOWTO use the Alfresco CMIS Browser Binding

The CMIS bindings of Alfresco are not very well documented. This is what I've found out.

Usage of the various encodings (using the curl -F and -d options) can probably be improved.

Get Node Metadata

$ curl -u 'admin:secret'\
http://host/alfresco/api/-default-/public/cmis/versions/1.1/browser/root?objectId=89098071-2422-4b13-ad34-655e8cc17921&cmisselector=object'

Note that it is possible to query directly on the root. Together with the objectId query parameter, this is enough to address the node.

The query parameter cmisselector must have the value object to get the node metadata.

This query returns application/json.

Get Node Content

$ curl -u 'admin:secret' \
'http://host/alfresco/api/-default-/public/cmis/versions/1.1/browser/root?objectId=89098071-2422-4b13-ad34-655e8cc17921'

Without the cmisselector query parameter, the node content is returned.

Search for Node by objectId

It is also possible to search for a node using a CMIS query.

$ curl -u 'admin:secret' \
-F cmisaction=query \
-F "statement=SELECT * FROM cmis:document WHERE cmis:objectId = '89098071-2422-4b13-ad34-655e8cc17921'" \
http://host/alfresco/api/-default-/public/cmis/versions/1.1/browser

There are two form parameters, cmisaction must have the value query, statement contains the CMIS query that matches the node with the objectId of the node.

Note that the response has a different structure: It is a JSON array with one element; only the properties specified in the SELECT are returned. If you want properties that are defined on a custom type or on aspects, you must use a CMIS JOIN to include them.

Search for Nodes

A similar request can be used to search for nodes.

$ curl -u 'admin:secret' \
-F cmisaction=query \
-F "statement=SELECT * FROM my:CustomType AS ct JOIN your:CustomAspect AS ca ON ct.cmis:objectId = ca.cmis:objectId WHERE ca.your:customProperty = 'some value' ORDER BY ct.my:sortProperty DESC" \
-F skipCount=0 \
-F maxItems=10 \
http://host/alfresco/api/-default-/public/cmis/versions/1.1/browser

This is very similar to the previous one, only the CMIS SELECT is different. It uses a JOIN to include properties of a custom type and a custom aspect. Without this, only the default CMIS properties would be included in the result and it would not be possible to to query on a custom property.

Note that aliases (ct and ca) are used in the FROM and in the WHERE condition. The join must be done ON ct.cmis:objectId = ca.cmis:objectId.

CMIS supports ORDER BY in the SELECT and skipCount and maxItems parameters.

Update Node Properties

$ curl -k -u 'admin:secret' \
-d 'cmisaction=update&propertyId[0]=my:customProperty&propertyValue[0]=some value' \
'http://host/alfresco/api/-default-/public/cmis/versions/1.1/browser/root?objectId=89098071-2422-4b13-ad34-655e8cc17921'

This time the cmisaction has the value update. The body also includes one pair of propertyId and propertyValue using an array notation.

Change Node Content

TODO

Create New Node

TODO

2017-12-12