Skip to main content

Create a virtual data room (VDR) with a watermark

This example demonstrates how to create a Virtual Data Room (VDR) in ONLYOFFICE DocSpace using the API. The room is created with a text watermark enabled, including dynamic elements such as UserName and CurrentDate.

Before you start

  1. Replace https://yourportal.onlyoffice.com and YOUR_API_KEY with your actual DocSpace portal URL and API key. Ensure you have the necessary data and permissions to perform migration operations.
  2. Before you can make requests to the API, you need to authenticate. Check out the Personal access tokens page to learn how to obtain and use access tokens.
Full example
// Set API base URL
const API_HOST = 'https://yourportal.onlyoffice.com';
const API_KEY = 'your_api_key';

// Headers with API key for authentication
const HEADERS = {
Authorization: `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
};

// Step 1: Create a Virtual Data Room with a text watermark
function createVdrRoom(roomTitle, roomDescription) {
const url = `${API_HOST}/api/2.0/files/rooms`;
const data = {
title: roomTitle,
description: roomDescription,
roomType: 8, // VDR room
watermark: {
enabled: true,
text: 'Confidential',
rotate: -45,
additions: 1, // Adds UserName
},
};

return fetch(url, {
method: 'POST',
headers: HEADERS,
body: JSON.stringify(data),
})
.then(async (res) => {
if (res.status === 200) return res.json();
const text = await res.text();
console.log(`VDR room creation failed. Status code: ${res.status}, Message: ${text}`);
return null;
})
.catch((err) => {
console.log(`VDR room creation error: ${err.message}`);
return null;
});
}

// Run
const roomTitle = 'Secure VDR Room';
const roomDescription = 'A virtual room with a confidential watermark.';

createVdrRoom(roomTitle, roomDescription);

How it works

A POST request is sent to /api/2.0/files/rooms with:

  • roomType: 8 indicating a Virtual Data Room (VDR).
  • watermark: Object containing watermark configuration:
    • enabled: True — enable watermarking.
    • text: Main watermark text.
    • rotate: Rotation angle for the watermark.
    • additions: Set to 1 to include dynamic data like UserName.