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/listChildren?folderId=4

The result is:

In this case you can see the result in JSON format. Some endpoints can also provide the results in XML format but you have to check them, if that is supported we can make a call sending the appropriate Accept header:

$ curl -u admin:admin -H "Accept: application/xml" \ http://localhost:8080/logicaldoc/services/rest/folder/listChildren?folderId=4

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: text/plain" -d "/Default/Curl/newfolder" \ http://localhost:8080/logicaldoc/services/rest/folder/createSimple

Creates a path of folders starting from the folder with ID 4 (Default folder)

$ curl -u admin:admin -H "Accept: application/json" \ -X POST -H "Content-Type: application/x-www-form-urlencoded" -d parentId=4 -d path=How/to/POST/JSON/data/with/Curl \ http://localhost:8080/logicaldoc/services/rest/folder/createPath

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 folderId=4 -F filename=CHANGELOG.txt -F filedata=@CHANGELOG.txt \ http://localhost:8080/logicaldoc/services/rest/document/upload

In this case the document will be added to the respository using the default language (english). Of course it is possible to specify the additional parameter 'language' to tell the system that the document we are storing is in german (ISO 639-2 code)

$ curl -u admin:admin -H "Accept: application/json" \ -X POST -F folderId=4 -F filename=pub_arbeitsplatz_straße.pdf -F language=de -F filedata=@pub_arbeitsplatz_straße.pdf \ http://localhost:8080/logicaldoc/services/rest/document/upload

Or also from a HTML form:

And now download it:

$ curl -u admin:admin \ http://localhost:8080/logicaldoc/services/rest/document/getContent?docId=456456456

If the document is a binary file you can redirect the output to a file adding '> filename' to the end of the command

$ curl -u admin:admin \ http://localhost:8080/logicaldoc/services/rest/document/getContent?docId=456456456 > myFile.pdf

Delete a specific version of a given document

$ curl -u admin:admin \ -G -d docId=1803 -d version=1.3 -X DELETE http://localhost:8080/services/rest/document/deleteVersion

Search
Standard Full-text search on content, title and tags using english as language of the query (expressionLanguage) and on english documents (language):

$ curl -u admin:admin -H "Content-Type: application/json" -H "Accept: application/json" -X POST \ -d "{\"maxHits\":50,\"expression\":\"document management system\",\"expressionLanguage\":\"en\",\"language\":\"en\"}" http://localhost:8080/logicaldoc/services/rest/search/find

More info at:


 * curl tutorial with examples of usage
 * LogicalDOC REST API reference
 * Webservices - Binding and Examples