RESTful Guide with curl: Difference between revisions

From LogicalDOC Community Wiki
Jump to navigationJump to search
Created page with "{{TOCright}} __TOC__ {{Note|If you're interested in use LogicalDOC API we suggest to '''take a look at ours ACACACACAC and take advantage of already usable libraries which c..."
 
 
(78 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{TOCright}} __TOC__
{{TOCright}} __TOC__


{{Note|If you're interested in use LogicalDOC API we suggest to '''take a look at ours [[ACACACACAC]] and take advantage of already usable libraries which connect to webservices API.}}
{{Note|If you're interested in use LogicalDOC API we suggest to '''take a look at ours [[Bindings_And_Samples|Bindings and Samples]] and take advantage of already usable examples which connect to webservices API.}}


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 [[Third-party system integration|integrate with third-party applications]] like a CRM or a CMS.
LogicalDOC has a [http://docs.logicaldoc.com/en/web-services-api 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.


{{Advice|For now this API is only available since LogicalDOC Professional 6.2.20 and 6.4.2. This API is in development, so expect changes.}}
{{Advice|Examples in this page refer to LogicalDOC 7.7; the [http://docs.logicaldoc.com/en/web-services-api REST API] is currently in development, so expect changes and additions.}}


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.
If you point your browser to http://localhost:8080/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 ==
== 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:
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:


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


The result is:
The result is:


<source lang="text">
<pre>
{"folders":
[
  {"folder":
  {
     [
    "id": 3440640,
      { "author":"admin",
    "name": "alfa",
        "created":"2013-07-29T12:09:11+02:00",
     "parentId": 4,
        "path":"\/okm:root\/alfa",
    "description": "",
        "permissions":15,
    "lastModified": "2016-06-15 15:49:40 +0200",
        "subscribed":false,
    "type": 0,
        "uuid":"6b3e0531-96a9-4675-bb82-215b715b20ca",
    "templateId": null,
        "hasChildren":false },
    "templateLocked": 0,
      { "author":"admin",
    "creation": "2016-06-15 15:49:40 +0200",
        "created":"2013-07-24T22:56:20+02:00",
    "creator": "Admin Admin",
        "path":"\/okm:root\/beta",
    "position": 1,
        "permissions":15,
    "hidden": 0,
        "subscribed":false,
    "foldRef": null,
        "uuid":"41f1bace-58b4-41a9-b43e-dffc1ac9a954",
    "attributes": [
        "hasChildren":false}
     
    ]
  },
  {
    "id": 3440643,
    "name": "beta",
    "parentId": 4,
    "description": "",
    "lastModified": "2016-06-16 10:16:25 +0200",
    "type": 0,
    "templateId": null,
    "templateLocked": 0,
    "creation": "2016-06-16 09:49:27 +0200",
    "creator": "Admin Admin",
    "position": 1,
    "hidden": 0,
    "foldRef": null,
    "attributes": [
     
     ]
     ]
   }
   }
}
]
</source>
</pre>


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:
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:


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


The result in XML is:
The result in XML is:


<source lang="xml">
<syntaxhighlight lang="xml">
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml version="1.0" encoding="UTF-8"?>
<folders>
<folders>
   <folder>
   <folder>
     <author>admin</author>
     <creation>2016-06-15 15:49:40 +0200</creation>
     <created>2013-07-29T12:09:11+02:00</created>
    <creator>Admin Admin</creator>
     <path>/okm:root/alfa</path>
    <description></description>
     <permissions>15</permissions>
    <hidden>0</hidden>
     <subscribed>false</subscribed>
    <id>3440640</id>
     <uuid>6b3e0531-96a9-4675-bb82-215b715b20ca</uuid>
     <lastModified>2016-06-15 15:49:40 +0200</lastModified>
     <hasChildren>false</hasChildren>
     <name>alfa</name>
     <parentId>4</parentId>
     <position>1</position>
     <templateLocked>0</templateLocked>
     <type>0</type>
   </folder>
   </folder>
   <folder>
   <folder>
     <author>admin</author>
     <creation>2016-06-16 09:49:27 +0200</creation>
     <created>2013-07-24T22:56:20+02:00</created>
     <creator>Admin Admin</creator>
     <path>/okm:root/beta</path>
    <description></description>
     <permissions>15</permissions>
    <hidden>0</hidden>
     <subscribed>false</subscribed>
    <id>3440643</id>
     <uuid>41f1bace-58b4-41a9-b43e-dffc1ac9a954</uuid>
    <lastModified>2016-06-16 10:16:25 +0200</lastModified>
     <hasChildren>false</hasChildren>
     <name>beta</name>
     <parentId>4</parentId>
     <position>1</position>
     <templateLocked>0</templateLocked>
     <type>0</type>
   </folder>
   </folder>
</folders>
</folders>
</source>
</syntaxhighlight>


This is a Java client for the same call:
This is a Java client for the same call:


<source lang="java">
<syntaxhighlight lang="java">
import java.io.BufferedReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.IOException;
Line 86: Line 117:
     public static void main(String[] args) throws Exception {
     public static void main(String[] args) throws Exception {
         try {
         try {
             String fldUuid = "3492d662-b58e-417c-85b6-930ad0c6c3cf";
             long folderID = 4L;
             URL url = new URL("http://localhost:8080/logicaldoc/services/rest/folder/getChildren?fldId=" + fldUuid);
             URL url = new URL("http://localhost:8080/services/rest/folder/listChildren?folderId=" + folderID);
             HttpURLConnection conn = (HttpURLConnection) url.openConnection();
             HttpURLConnection conn = (HttpURLConnection) url.openConnection();
             conn.setRequestMethod("GET");
             conn.setRequestMethod("GET");
Line 118: Line 149:
     }
     }
}
}
</source>
</syntaxhighlight>


== Folder ==
== Folder ==
Let's create a new folder:
Let's create a new folder:


<syntaxhighlight lang="bash">
  $ curl -u admin:admin -H "Accept: application/json" \
    -X POST -H "Content-Type: text/plain" -d "/Default/Curl/newfolder" \
    http://localhost:8080/services/rest/folder/createSimple
</syntaxhighlight>
Creates a path of folders starting from the folder with ID 4 (Default folder)
<syntaxhighlight lang="bash">
   $ curl -u admin:admin -H "Accept: application/json" \
   $ curl -u admin:admin -H "Accept: application/json" \
     -X POST -H "Content-Type: application/json" -d '/okm:root/newfolder' \
     -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/createSimple
     http://localhost:8080/services/rest/folder/createPath
</syntaxhighlight>


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


<syntaxhighlight lang="bash">
   $ curl -u admin:admin -H "Accept: application/json" \
   $ curl -u admin:admin -H "Accept: application/json" \
     -X POST -F docPath=/okm:root/newDoc.txt -F content=@newDoc.txt \
     -X POST -F folderId=4 -F filename=CHANGELOG.txt -F filedata=@CHANGELOG.txt \
     http://localhost:8080/logicaldoc/services/rest/document/createSimple
    http://localhost:8080/services/rest/document/upload
</syntaxhighlight>
 
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)
 
<syntaxhighlight lang="bash">
  $ 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/services/rest/document/upload
</syntaxhighlight>
 
Creates a document with the create method on Windows 10<br/>
Windows 10, curl 7.55.1 (Windows) libcurl/7.55.1 WinSSL
 
<syntaxhighlight lang="bash">
  $ curl -v -u admin:admin -X POST "http://localhost:8080/services/rest/document/create" -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "document={ \"language\":\"en\",\"fileName\":\"ScreenHunter949.png\",\"folderId\":4 };type=application/json" -F "content=@C:\Users\shatz\Desktop\ScreenHunter949.png;type=application/octet-stream"
</syntaxhighlight>


Or also from a HTML form:
Or also from a HTML form:


<source lang="html4strict">
<syntaxhighlight lang="html4strict">
<html>
<html>
   <body>
   <body>
     <form method="POST" enctype="multipart/form-data"
     <form method="POST" enctype="multipart/form-data"
           action="http://localhost:8080/logicaldoc/services/rest/document/createSimple">
           action="http://localhost:8080/services/rest/document/upload">
       Select file: <input type="file" name="content" size="45"/><br/>
       Select folder: <input type="text" name="folderId" value="4"/><br/>
       Select path: <input type="text" name="docPath" value="/okm:root/newDoc.txt"/><br/>
       Select filename: <input type="text" name="filename" /><br/>
      Select file: <input type="file" name="filedata" size="45"/><br/>
       <input type="submit" value="Upload" />
       <input type="submit" value="Upload" />
     </form>
     </form>
   </body>
   </body>
</html>
</html>
</source>
</syntaxhighlight>
 
=== Create via Upload ===
Create a new document, or a new version of an existing document (in one step) [Windows 11]<br/>
This is a simpler way of creating documents, however it is more limited as it does not allow complete control of the metadata


And now download it:
<syntaxhighlight lang="bash">
  $ curl -u admin:admin -X POST "http://localhost:8080/services/rest/document/upload" \
    -H  "Accept: application/json" -H  "Content-Type: multipart/form-data" -F "docId=721" -F "folderId=" -F "release=false" \
    -F "filename=logicaldoc_community - Checkmarx AST.pdf" -F "language=en" -F "filedata=@logicaldoc_community - Checkmarx AST.pdf;type=application/pdf"
</syntaxhighlight>


   $ curl -u admin:admin \
Upload: updates the content of an existing document generating a new version
    http://localhost:8080/logicaldoc/services/rest/document/getContent?docId=58f79fa6-fe6e-4f68-8517-68a60898d122
<syntaxhighlight lang="bash">
   $ curl -v -u admin:admin -H "Accept: application/json" -X POST -F docId=118 -F filename=google.png -F filedata=@C:\tmp\google.png http://localhost:8080/services/rest/document/upload
</syntaxhighlight>


== Search ==
=== Update metadata ===
Search simply by content:
Update the document metadata. Specifically, we can see how to update an extended attribute field of type date (type = 3) using the property dateValue


   $ curl -u admin:admin -H "Accept: application/json" -X GET \
<syntaxhighlight lang="bash">
     http://localhost:8080/logicaldoc/services/rest/search/findByContent?content=santo+grial
   $ curl -v -u admin:admin -H "Content-Type: application/json" -H "Accept: application/json" -X PUT \
    -d "{ \"id\": 47, \"folderId\": 4, \"fileName\":\"Egzai_u002.doc\", \"templateId\":92241920, \"attributes\":[{\"name\":\"ack\",\"stringValue\":\"ack\",\"type\":0},{\"name\":\"Tar\",\"dateValue\":\"2017-03-18 19:10:00 +0100\",\"type\":3}] }" \  
     http://localhost:8080/services/rest/document/update
</syntaxhighlight>


Search by keyword:
=== Delete ===
Delete a specific version of a given document (since v7.6.4)


   $ curl -u admin:admin -H "Accept: application/json" -X GET \
<syntaxhighlight lang="bash">
    http://localhost:8080/logicaldoc/services/rest/search/findByKeywords?keyword=santo\&keyword=grial
   $ curl -u admin:admin \
    -G -d docId=1803 -d version=1.3 -X DELETE http://localhost:8080/services/rest/document/deleteVersion
</syntaxhighlight>


Or use a more customized search parameters:
=== Download ===


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


Even can query by Property Groups:
<syntaxhighlight lang="bash">
  $ curl -u admin:admin \
    http://localhost:8080/services/rest/document/getContent?docId=456456456
</syntaxhighlight>


   $ curl -u admin:admin -H "Accept: application/json" -X GET \
If the document is a binary file you can redirect the output to a file adding '> filename' to the end of the command
     http://localhost:8080/logicaldoc/services/rest/search/find?content=grial\&property='okp:name=alfa'
<syntaxhighlight lang="bash">
   $ curl -u admin:admin \
     http://localhost:8080/services/rest/document/getContent?docId=456456456 > myFile.pdf
</syntaxhighlight>


== Security ==
=== Convert a document to PDF ===
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 \
Note: This will only perform the conversion, if completed successfully it returns HTTP code 204 and empty content
    http://localhost:8080/logicaldoc/services/rest/auth/getGrantedUsers?nodeId=3492d662-b58e-417c-85b6-930ad0c6c3cf
<syntaxhighlight lang="bash">
   $ curl -v -X PUT "http://localhost:8080/services/rest/document/createPdf?docId=125" -H  "accept: application/json" -H  "Authorization: Basic YWRtaW46YWRtaW4="
</syntaxhighlight>


And now the granted roles:
Download the converted .PDF file (latest version of the document)
<syntaxhighlight lang="bash">
  $ curl -v -X GET "http://localhost:8080/services/rest/document/getResource?docId=125&suffix=conversion.pdf" -H  "accept: application/octet-stream" -H  "Authorization: Basic YWRtaW46YWRtaW4=" --output 125-conversion.pdf
</syntaxhighlight>


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


To grant some permissions do:
<syntaxhighlight lang="bash">
  $ curl -k -u admin:admin -X POST https://[url]/services/rest/document/checkout \
    -H  "accept: application/json" -H  "Content-Type: application/x-www-form-urlencoded" -d "docId=2686"
</syntaxhighlight>


   $ curl -v -u admin:admin -X PUT -H "Content-Type: application/x-www-form-urlencoded" \
Checkin a new version of document (the document must be in checked-out state) [Windows 11]<br/>
    -d user=john -d permissions=15 -d recursive=false -d nodeId=3492d662-b58e-417c-85b6-930ad0c6c3cf \
<syntaxhighlight lang="bash">
    http://localhost:8080/logicaldoc/services/rest/auth/grantUser
   $ curl -v -u admin:admin -X POST "http://localhost:8080/services/rest/document/checkin" \
    -H "accept: */*" -H  "Content-Type: multipart/form-data" -F "docId=721" -F "comment=" -F "release=false" -F "filename=Checkmarx.txt" -F "filedata=@Checkmarx.txt;type=text/plain"
</syntaxhighlight>


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


   $ curl -v -u admin:admin -X PUT -H "Content-Type: application/x-www-form-urlencoded" \
<syntaxhighlight lang="bash">
     -d user=john -d permissions=15 -d recursive=false -d nodeId=3492d662-b58e-417c-85b6-930ad0c6c3cf \
   $ curl -u admin:admin -H "Content-Type: application/json" -H "Accept: application/json" -X POST \
     http://localhost:8080/logicaldoc/services/rest/auth/revokeUser
     -d "{\"maxHits\":50,\"expression\":\"document management system\",\"expressionLanguage\":\"en\",\"language\":\"en\", \"dateFrom\": \"2023-01-01\"}"
     http://localhost:8080/services/rest/search/find
</syntaxhighlight>


== Property Groups ==
Date fields you can use:
In this example we add a property group:
<pre>
"dateFrom": "string",
"dateTo": "string",
"creationFrom": "string",
"creationTo": "string",
</pre>


  $ curl -u admin:admin -H "Accept: application/json" -X PUT \
dates must be expressed in ISO format: yyyy-mm-dd or yyyy-MM-dd HH:mm:ss (24 hours)
    http://localhost:8080/logicaldoc/services/rest/propertyGroup/addGroup?nodeId=3492d662-b58e-417c-85b6-930ad0c6c3cf\&grpName=okg:technology


And set some property group values:
== Tags ==
Set the document tags of document with ID = 325


   $ curl -u admin:admin -H "Accept: application/json" \
<syntaxhighlight lang="bash">
    -X PUT -H "Content-Type: application/xml" \
   $ curl -v -u admin:admin -X POST "http://localhost:8080/services/rest/tag/setDocumentTags" \
    -d '<simplePropertiesGroup><simplePropertyGroup><name>okp:technology.comment</name><value>RESTful rulez!</value></simplePropertyGroup></simplePropertiesGroup>' \
        -H "accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" \
    http://localhost:8080/logicaldoc/services/rest/propertyGroup/setPropertiesSimple?nodeId=3492d662-b58e-417c-85b6-930ad0c6c3cf\&grpName=okg:technology
        -d "docId=325" --data-urlencode "tag=fileExtension:docx" \
        --data-urlencode "tag=wopiLockString:1234567890123456789012345678901234567890123456789012345678901234567890"
</syntaxhighlight>


== Notes ==
== Upload Resource ==
To create a note in a LogicalDOC folder or document you can do this (previously you need to know the node UUID):


  $ curl -u admin:admin -H "Accept: application/json" \
Uploads a resource of an existing document: thumbnail, tile, or preview.<br/>
    -X POST -H "Content-Type: application/json" -d 'Hello, world!' \
The following example uploads the tile image (suffix: tile.png)
    http://localhost:8080/logicaldoc/services/rest/note/add?nodeId=3492d662-b58e-417c-85b6-930ad0c6c3cf


<syntaxhighlight lang="bash">
curl -X "POST" ^
  "http://localhost:8080/services/rest/document/uploadResource" ^
  -H "accept: */*" ^
  -H "Authorization: Basic YWRtaW46YWRtaW4=" ^
  -H "Content-Type: multipart/form-data" ^
  -F "docId=10075" ^
  -F "fileVersion=1.0" ^
  -F "suffix=tile.png" ^
  -F "content=@folder32.png;type=image/png"
</syntaxhighlight>


More info at:
More info at:


* [http://www.yilmazhuseyin.com/blog/dev/curl-tutorial-examples-usage/ curl tutorial with examples of usage]
* [http://www.yilmazhuseyin.com/blog/dev/curl-tutorial-examples-usage/ curl tutorial with examples of usage]
* [http://docs.logicaldoc.com/resources/wsdoc/rest/index.html?version=7.6.4 LogicalDOC REST API reference v7.6.4]
* [https://docs.logicaldoc.com/resources/wsdoc/rest/index.html?version=7.7.6 LogicalDOC REST API reference v7.7.6]
* [https://docs.logicaldoc.com/resources/wsdoc/rest/index.html?version=8.1.0 LogicalDOC REST API reference v8.1]
* [https://docs.logicaldoc.com/resources/wsdoc/rest/9.1.1/index.html LogicalDOC REST API reference v9.1.1]
* [https://app.swaggerhub.com/apis/swatzniak/logicaldoc_rest_api/8.8.1 LogicalDOC REST API | 8.8.1 | SwaggerHub]
* [[Bindings_And_Samples|Webservices - Binding and Examples]]
* [https://docs.logicaldoc.com/en/web-services-api LogicalDOC Web Services API]
[[Category: RESTful Guide]]
[[Category: RESTful Guide]]

Latest revision as of 09:58, 30 May 2025


If you're interested in use LogicalDOC API we suggest to take a look at ours Bindings and Samples and take advantage of already usable examples which connect to webservices API.


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.


Examples in this page refer to LogicalDOC 7.7; the REST API is currently in development, so expect changes and additions.


If you point your browser to http://localhost:8080/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/services/rest/folder/listChildren?folderId=4

The result is:

[
  {
    "id": 3440640,
    "name": "alfa",
    "parentId": 4,
    "description": "",
    "lastModified": "2016-06-15 15:49:40 +0200",
    "type": 0,
    "templateId": null,
    "templateLocked": 0,
    "creation": "2016-06-15 15:49:40 +0200",
    "creator": "Admin Admin",
    "position": 1,
    "hidden": 0,
    "foldRef": null,
    "attributes": [
      
    ]
  },
  {
    "id": 3440643,
    "name": "beta",
    "parentId": 4,
    "description": "",
    "lastModified": "2016-06-16 10:16:25 +0200",
    "type": 0,
    "templateId": null,
    "templateLocked": 0,
    "creation": "2016-06-16 09:49:27 +0200",
    "creator": "Admin Admin",
    "position": 1,
    "hidden": 0,
    "foldRef": null,
    "attributes": [
      
    ]
  }
]

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

The result in XML is:

<?xml version="1.0" encoding="UTF-8"?>
<folders>
  <folder>
    <creation>2016-06-15 15:49:40 +0200</creation>
    <creator>Admin Admin</creator>
    <description></description>
    <hidden>0</hidden>
    <id>3440640</id>
    <lastModified>2016-06-15 15:49:40 +0200</lastModified>
    <name>alfa</name>
    <parentId>4</parentId>
    <position>1</position>
    <templateLocked>0</templateLocked>
    <type>0</type>
  </folder>
  <folder>
    <creation>2016-06-16 09:49:27 +0200</creation>
    <creator>Admin Admin</creator>
    <description></description>
    <hidden>0</hidden>
    <id>3440643</id>
    <lastModified>2016-06-16 10:16:25 +0200</lastModified>
    <name>beta</name>
    <parentId>4</parentId>
    <position>1</position>
    <templateLocked>0</templateLocked>
    <type>0</type>
  </folder>
</folders>

This is a Java client for the same call:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.PasswordAuthentication;
import java.net.URL;

public class JavaRestClient {
    public static void main(String[] args) throws Exception {
        try {
            long folderID = 4L;
            URL url = new URL("http://localhost:8080/services/rest/folder/listChildren?folderId=" + folderID);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            conn.setRequestProperty("Accept", "application/json");
            
            Authenticator.setDefault(new Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication("admin", "admin".toCharArray());
                }
            });
            
            if (conn.getResponseCode() == 200) {
                BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
                System.out.println("Output from Server .... \n");
                String output;
                
                while ((output = br.readLine()) != null) {
                    System.out.println(output);
                }
            } else {
                System.err.println("Failed : HTTP error code : " + conn.getResponseCode());
            }
            
            conn.disconnect();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

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/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/services/rest/folder/createPath

Document

Create a 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/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/services/rest/document/upload

Creates a document with the create method on Windows 10
Windows 10, curl 7.55.1 (Windows) libcurl/7.55.1 WinSSL

  $ curl -v -u admin:admin -X POST "http://localhost:8080/services/rest/document/create" -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "document={ \"language\":\"en\",\"fileName\":\"ScreenHunter949.png\",\"folderId\":4 };type=application/json" -F "content=@C:\Users\shatz\Desktop\ScreenHunter949.png;type=application/octet-stream"

Or also from a HTML form:

<html>
  <body>
    <form method="POST" enctype="multipart/form-data"
          action="http://localhost:8080/services/rest/document/upload">
      Select folder: <input type="text" name="folderId" value="4"/><br/>
      Select filename: <input type="text" name="filename" /><br/>
      Select file: <input type="file" name="filedata" size="45"/><br/>
      <input type="submit" value="Upload" />
    </form>
  </body>
</html>

Create via Upload

Create a new document, or a new version of an existing document (in one step) [Windows 11]
This is a simpler way of creating documents, however it is more limited as it does not allow complete control of the metadata

  $ curl -u admin:admin -X POST "http://localhost:8080/services/rest/document/upload" \
    -H  "Accept: application/json" -H  "Content-Type: multipart/form-data" -F "docId=721" -F "folderId=" -F "release=false" \
    -F "filename=logicaldoc_community - Checkmarx AST.pdf" -F "language=en" -F "filedata=@logicaldoc_community - Checkmarx AST.pdf;type=application/pdf"

Upload: updates the content of an existing document generating a new version

  $ curl -v -u admin:admin -H "Accept: application/json" -X POST -F docId=118 -F filename=google.png -F filedata=@C:\tmp\google.png http://localhost:8080/services/rest/document/upload

Update metadata

Update the document metadata. Specifically, we can see how to update an extended attribute field of type date (type = 3) using the property dateValue

  $ curl -v -u admin:admin -H "Content-Type: application/json" -H "Accept: application/json" -X PUT \
    -d "{ \"id\": 47, \"folderId\": 4, \"fileName\":\"Egzai_u002.doc\", \"templateId\":92241920, \"attributes\":[{\"name\":\"ack\",\"stringValue\":\"ack\",\"type\":0},{\"name\":\"Tar\",\"dateValue\":\"2017-03-18 19:10:00 +0100\",\"type\":3}] }" \ 
    http://localhost:8080/services/rest/document/update

Delete

Delete a specific version of a given document (since v7.6.4)

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

Download

And now download it:

  $ curl -u admin:admin \
    http://localhost:8080/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/services/rest/document/getContent?docId=456456456 > myFile.pdf

Convert a document to PDF

Note: This will only perform the conversion, if completed successfully it returns HTTP code 204 and empty content

  $ curl -v -X PUT "http://localhost:8080/services/rest/document/createPdf?docId=125" -H  "accept: application/json" -H  "Authorization: Basic YWRtaW46YWRtaW4="

Download the converted .PDF file (latest version of the document)

  $ curl -v -X GET "http://localhost:8080/services/rest/document/getResource?docId=125&suffix=conversion.pdf" -H  "accept: application/octet-stream" -H  "Authorization: Basic YWRtaW46YWRtaW4=" --output 125-conversion.pdf

Versioning

Checkout an existing document

  $ curl -k -u admin:admin -X POST https://[url]/services/rest/document/checkout \
    -H  "accept: application/json" -H  "Content-Type: application/x-www-form-urlencoded" -d "docId=2686"

Checkin a new version of document (the document must be in checked-out state) [Windows 11]

  $ curl -v -u admin:admin -X POST "http://localhost:8080/services/rest/document/checkin" \
    -H  "accept: */*" -H  "Content-Type: multipart/form-data" -F "docId=721" -F "comment=" -F "release=false" -F "filename=Checkmarx.txt" -F "filedata=@Checkmarx.txt;type=text/plain"

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\", \"dateFrom\": \"2023-01-01\"}" 
    http://localhost:8080/services/rest/search/find

Date fields you can use:

"dateFrom": "string", 
"dateTo": "string", 
"creationFrom": "string", 
"creationTo": "string",

dates must be expressed in ISO format: yyyy-mm-dd or yyyy-MM-dd HH:mm:ss (24 hours)

Tags

Set the document tags of document with ID = 325

  $ curl -v -u admin:admin -X POST "http://localhost:8080/services/rest/tag/setDocumentTags" \
         -H "accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" \
         -d "docId=325" --data-urlencode "tag=fileExtension:docx" \
        --data-urlencode "tag=wopiLockString:1234567890123456789012345678901234567890123456789012345678901234567890"

Upload Resource

Uploads a resource of an existing document: thumbnail, tile, or preview.
The following example uploads the tile image (suffix: tile.png)

curl -X "POST" ^
  "http://localhost:8080/services/rest/document/uploadResource" ^
  -H "accept: */*" ^
  -H "Authorization: Basic YWRtaW46YWRtaW4=" ^
  -H "Content-Type: multipart/form-data" ^
  -F "docId=10075" ^
  -F "fileVersion=1.0" ^
  -F "suffix=tile.png" ^
  -F "content=@folder32.png;type=image/png"

More info at: