How to Update Documents

→ "Try it out - API Component "YADB"
→ check GitHub Python calls | Java Script calls | Java calls | Postman collection


This "How to" describes how to update documents (objects) in your schema using yuuvis® Ultimate operations.

Updating Documents

Updating Metadata

To update the metadata of a stored document (object), you can choose from two endpoints yuuvis offers for that purpose, one using the PATCH and the other using the POST method. The POST method is a complete update and thus requires a complete set of the values of all non-system properties, while the PATCH method allows you to update the values of individual properties of a metadata set while leaving other values unchanged. Typically, you perform a GET before updating via POST, while PATCH can be used to change a value without further knowledge of the other properties.

The syntax for POST and PATCH is the same.

For a partial update of an object's metadata, you send a PATCH request to the URL /dms-core/objects/{objectId} with the new metadata values in its body ("PATCH update document metadata by ID" endpoint.)

For a complete update of an object's metadata, you send a POST request to the URL /dms-core/objects/{objectId} with the new metadata values in its body ("POST update document metadata by ID" endpoint.)

Note that instead of using a multipart body, the new metadata is passed to the body as a string and specified as JSON media type.

Updating Metadata
Request updateMetadataRequest = new Request.Builder()
        .header("Ocp-Apim-Subscription-Key", key)
        .url(baseUrl + "/dms-core/objects/" + objectId)
        .post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"),
			new File("./src/main/resources/metaData2.json")))
        .build();

The response returns the full, modified metadata with a new version number.

Note

Most of the system properties cannot be updated or are updated automatically. If the new metadata contains these properties, their values must match the values of the current version.

Updating Content

To update the content file of a stored document (object), you send a POST request to the URL /dms-core/objects/{objectId}/contents/file with the new content file in its body ("POST update document content by ID" endpoint). Specify the file name of the content file via the Content-Disposition header.

Updating Content
Request updateContentRequest = new Request.Builder()
        .header("Ocp-Apim-Subscription-Key", key)
        .header("Content-Disposition", "attachment; filename=\"test2.txt\"")
        .url(baseUrl + "/dms-core/objects/" + objectId + "/contents/file")
        .post(RequestBody.create(MediaType.parse("text/plain; charset=utf-8"), 
			new File("./src/main/resources/test2.txt")))
        .build();

Responses

Status Code Meaning
200 OK
401 Unauthorized
422 Invalid Request Body

Versioning

Each time you update either the content file or the metadata of a stored document (object), a new version is created. The endpoints for fetching metadata (/dms-core/objects/{objectId}) or content files (/dms-core/objects/{objectId}/contents/file) always return the current version. Check out the following options to get a content file or metadata related to an older version.

Retrieving Version Related Metadata

To retrieve metadata of a version, you send a GET request to the URL /dms-core/objects/{objectId}/versions/{versionNr} ("Get document metadata by ID (specified version)" endpoint). The versionNr for each object starts at 1 and is incremented with each update.

Get Metadata of Version 1
Request versionMetadataRequest = new Request.Builder()
        .header("Ocp-Apim-Subscription-Key", key)
        .url(baseUrl+ "/dms/objects/" + objectId + "/versions/1")
        .get().build();

Retrieving Version Related Content

To retrieve the content file of a version, you send a GET request to the URL /dms-core/objects/{objectId}/versions/{versionNr}/contents/file ("Get document content by ID (specified version)" endpoint.

Get Content File of Version 2
Request versionContentRequest = new Request.Builder()
        .header("Ocp-Apim-Subscription-Key", key)
        .url(baseUrl+ "/dms-core/objects/" + objectId + "/versions/2/contents/file")
        .get().build();