1. Introduction
In this tutorial, we will update the metadata of one single DMS object and of multiple DMS objects in a batch request.
2. Requirements
Please work through the following tutorials to get prepared:
3. Java Libraries
Import the following Java libraries (if not already done).
import okhttp3.*;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.CookieManager;
import java.net.CookiePolicy;
import java.util.Base64;
4. Variables with Login and Content Types Configuration
Specify your access credentials and content type configurations (if not already done).
Specify the objectId variable.
public static final String username = "root";
public static final String userpassword = "changeme";
public static final String auth = "Basic "+ Base64.getEncoder().encodeToString((username+":"+userpassword).getBytes());
public static final String tenant = "myfirsttenant";
public static final String baseUrl = "http://123.456.78.9:30080";
public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
public static final MediaType JPEG = MediaType.parse("image/jpeg; charset=utf-8");
5. Client
To send our requests, we again use the Java client.
try {
CookieJar cookieJar = new JavaNetCookieJar(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
OkHttpClient client = new OkHttpClient.Builder().cookieJar(cookieJar).build();
} catch (Exception e) {
e.printStackTrace();
}
6. Initial Import
We will import an image file and create a very basic DMS document object with only system properties.
{
"objects": [{
"properties": {
"objectTypeId": {
"value": "system:document"
}
},
"contentStreams": [{
"fileName": "1080px-Deilenaar.jpeg",
"cid": "cid0"
}]
}]
}
RequestBody singleImportRequestBody = new MultipartBody
.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("data",
"metadata.json",
RequestBody.create(JSON,
new File("./src/main/resources/metadataRabbit.json")))
.addFormDataPart("cid0",
"1080px-Deilenaar.jpeg",
RequestBody.create(JPEG,
new File("./src/main/resources/1080px-Deilenaar.jpeg")))
.build();
Request singleImportRequest = new Request.Builder()
.header("Authorization", auth)
.header("X-ID-TENANT-NAME", tenant)
.url(baseUrl + "/api/dms/objects")
.post(singleImportRequestBody)
.build();
Response response = client.newCall(singleImportRequest).execute();
String responseString = response.body().string();
System.out.println(responseString);
JSONObject jsonObject = new JSONObject(responseString);
String objectId = jsonObject.getJSONArray("objects")
.getJSONObject(0)
.getJSONObject("properties")
.getJSONObject("system:objectId")
.getString("value");
System.out.println(objectId);
Reuse the objectId variable and its value for the next section.
7. Patch Update Metadata
We now want to add custom properties to the object’s metadata. Therefore, we assign a secondary object type. This will enable the usage of all properties that are referenced in its definition in the schema.
{
"objects": [{
"properties": {
"secondaryObjectTypeIds": {
"value": ["appPetshop:pet"]
},
"appPetshop:breed": {
"value": "Deilenaar"
},
"appPetshop:species": {
"value": "rabbit"
},
"appPetshop:dateOfBirth": {
"value": "2025-11-20T16:18:06.478Z"
},
"appPetshop:price": {
"value": "30.50"
}
}
}]
}
The endpoint (PATCH /api/dms/objects/{objectId}) can be used to update or add only those properties provided in the request body.
Request patchMetadataRequest = new Request.Builder()
.header("Authorization", auth)
.header("X-ID-TENANT-NAME", tenant)
.url(baseUrl + "/api/dms/objects/" + objectId)
.patch(RequestBody.create(JSON, new File("./src/main/resources/metadataRabbitUpdate.json")))
.build();