RESTful Guide with curl

LogicalDOC has a complete API exposed via REST. This means you can call any of these API methods from any programming language, like Java, PHP or Python among others. This feature makes it possible to create a custom client, or integrate with third-party applications like a CRM or a CMS.

If you point your browser to http://localhost:8080/logicaldoc/services, you can see the SOAP API at first place but at the bottom you will see a Available RESTful services section. These URLs are protected by BASIC authentication so you need to provide an user and password to access them.

Sample usage
To try these API methods you can use an HTTP Client library or any REST client which ease this process. Or simply you can use the curl command-line application. For example, you can list the children folders:

$ curl -u admin:admin -H "Accept: application/json" \ http://localhost:8080/logicaldoc/services/rest/folder/getChildren?fldId=3492d662-b58e-417c-85b6-930ad0c6c3cf

The result is:

In this case you can see the result in JSON format. Otherwise you can need an XML output, which can be forced using the 'Accept header:

$ curl -u admin:admin -H "Accept: application/xml" \ http://localhost:8080/logicaldoc/services/rest/folder/getChildren?fldId=3492d662-b58e-417c-85b6-930ad0c6c3cf

The result in XML is:

This is a Java client for the same call:

Folder
Let's create a new folder:

$ curl -u admin:admin -H "Accept: application/json" \ -X POST -H "Content-Type: application/json" -d '/okm:root/newfolder' \ http://localhost:8080/logicaldoc/services/rest/folder/createSimple

Document
Now we are going to create a document. For this, we need to provide the document binary data:

$ curl -u admin:admin -H "Accept: application/json" \ -X POST -F docPath=/okm:root/newDoc.txt -F content=@newDoc.txt \ http://localhost:8080/logicaldoc/services/rest/document/createSimple

Or also from a HTML form:

And now download it:

$ curl -u admin:admin \ http://localhost:8080/logicaldoc/services/rest/document/getContent?docId=58f79fa6-fe6e-4f68-8517-68a60898d122

Search
Search simply by content:

$ curl -u admin:admin -H "Accept: application/json" -X GET \ http://localhost:8080/logicaldoc/services/rest/search/findByContent?content=santo+grial

Search by keyword:

$ curl -u admin:admin -H "Accept: application/json" -X GET \ http://localhost:8080/logicaldoc/services/rest/search/findByKeywords?keyword=santo\&keyword=grial

Or use a more customized search parameters:

$ curl -u admin:admin -H "Accept: application/json" -X GET \ http://localhost:8080/logicaldoc/services/rest/search/find?content=grial\&mimeType=application/pdf

Even can query by Property Groups:

$ curl -u admin:admin -H "Accept: application/json" -X GET \ http://localhost:8080/logicaldoc/services/rest/search/find?content=grial\&property='okp:name=alfa'

Security
Let's see the security info associated to a given node. First show granted users:

$ curl -u admin:admin -H "Accept: application/json" -X GET \ http://localhost:8080/logicaldoc/services/rest/auth/getGrantedUsers?nodeId=3492d662-b58e-417c-85b6-930ad0c6c3cf

And now the granted roles:

$ curl -u admin:admin -H "Accept: application/json" -X GET \ http://localhost:8080/logicaldoc/services/rest/auth/getGrantedRoles?nodeId=3492d662-b58e-417c-85b6-930ad0c6c3cf

To grant some permissions do:

$ curl -v -u admin:admin -X PUT -H "Content-Type: application/x-www-form-urlencoded" \ -d user=john -d permissions=15 -d recursive=false -d nodeId=3492d662-b58e-417c-85b6-930ad0c6c3cf \ http://localhost:8080/logicaldoc/services/rest/auth/grantUser

And revoke using:

$ curl -v -u admin:admin -X PUT -H "Content-Type: application/x-www-form-urlencoded" \ -d user=john -d permissions=15 -d recursive=false -d nodeId=3492d662-b58e-417c-85b6-930ad0c6c3cf \ http://localhost:8080/logicaldoc/services/rest/auth/revokeUser

Property Groups
In this example we add a property group:

$ curl -u admin:admin -H "Accept: application/json" -X PUT \ http://localhost:8080/logicaldoc/services/rest/propertyGroup/addGroup?nodeId=3492d662-b58e-417c-85b6-930ad0c6c3cf\&grpName=okg:technology

And set some property group values:

$ curl -u admin:admin -H "Accept: application/json" \ -X PUT -H "Content-Type: application/xml" \ -d ' okp:technology.comment RESTful rulez! ' \ http://localhost:8080/logicaldoc/services/rest/propertyGroup/setPropertiesSimple?nodeId=3492d662-b58e-417c-85b6-930ad0c6c3cf\&grpName=okg:technology