Deleting Documents via Core API
This tutorial explains how documents can be deleted using the Core API with the help of a Java client. This tutorial requires basic knowledge of importing documents using the Core API.
Check out our graphical overview of the architecture which describes the basic use case flow for deleting content.
Table of Contents
Requirements
To work through this tutorial, the following is required:
- Set-up yuuvis® API system (see Installation Guide)
- A user with read and delete permissions on a document type in the system (see tutorial for permissions)
- Simple Maven project
Maven Configuration
Our Java client will submit its requests to the Core API using OkHttp 3.12 by Square, Inc. Therefore, the following block must be added to the Maven dependencies in the pom.xml
of the project:
<dependency> <groupId>com.squareup.okhttp3</groupId> <artifactId>okhttp</artifactId> <version>3.12.0</version> </dependency>
Client Configuration
To interact with the yuuvis® API system via the Core API, we use an OkHttp3 client to send HTTP requests and read their responses.
String baseUrl = "http://127.0.0.1"; //baseUrl of gateway: "http://<host>:<port>" String username = "clouduser"; String userpassword = "secret"; String tenant = "default"; String auth = java.util.Base64.getEncoder().encodeToString((username + ":" + userpassword).getBytes()); OkHttpClient.Builder builder = new OkHttpClient.Builder(); OkHttpClient client = builder.build();
For more information on setting up the OkHttp3 client with cookie handling, please refer to this Login Tutorial.
Deleting a Document
To delete a document from the system, a DELETE request must be sent to the endpoint /api/dms/objects/{objectId}
for the corresponding object ID. This deletes the metadata record and, if present, the content file.
Request deleteRequest = new Request.Builder() .header("Authorization", "Basic "+ auth) .header("X-ID-TENANT-NAME", tenant) .url(baseUrl + "/api/dms/objects/" + objectId) //baseUrl: "http://<host>:<port>" .delete().build();
Deleting a Version of a Document
To delete a version of a document from the system, a DELETE request must be sent to the endpoint /api/dms/objects/{objectId}/versions/{versionNr}
. The corresponding version number must exist for the document. If the specified version number indicates the current version of the document, the entire document including all associated versions will be deleted.
Request deleteVersionRequest = new Request.Builder() .header("X-ID-TENANT-NAME", "default") .header("Authorization", "Basic "+ auth) .url(baseUrl + "objects/"+objectId+"/versions/1") //baseUrl: "http://<host>:<port>" .delete().build(); Response deleteVersionResponse = client.newCall(deleteVersionRequest).execute();
Deleting a Referencing Document
When deleting referencing documents (objects whose contentStreams
object refers to existing content in the system during import), note that the corresponding content is deleted in the entire system and is also no longer available for the original object after deletion.
Deleting Compound Documents
Deleting compound documents is different. This article describes what compound documents are and what to consider when deleting compound documents.
Summary
In this tutorial an OkHttpClient with cookie handling was used to delete an object or a certain version of the object.
The complete code example can be found in the Git repository.