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
- Replace
https://yourportal.onlyoffice.comandYOUR_API_KEYwith your actual DocSpace portal URL and API key. Ensure you have the necessary data and permissions to perform migration operations. - 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
- Node.js
- Python
// 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);
import requests
# Set API base URL
API_HOST = 'https://yourportal.onlyoffice.com'
API_KEY = 'your_api_key'
# Headers with API key for authentication
HEADERS = {
'Authorization': f'Bearer {API_KEY}'
}
# Step 1: Create a Virtual Data Room with a text watermark
def create_vdr_room(room_title, room_description):
url = f'{API_HOST}/api/2.0/files/rooms'
data = {
'title': room_title,
'description': room_description,
'roomType': 8, # VDR room
'watermark': {
'enabled': True,
'text': 'Confidential',
'rotate': -45,
'additions': 1 # Adds UserName
}
}
response = requests.post(url, headers=HEADERS, json=data)
if response.status_code == 200:
return response.json()
else:
print(f"VDR room creation failed. Status code: {response.status_code}, Message: {response.text}")
return None
if __name__ == "__main__":
room_title = 'Secure VDR Room'
room_description = 'A virtual room with a confidential watermark.'
create_vdr_room(room_title, room_description)
How it works
A POST request is sent to /api/2.0/files/rooms with:
roomType:8indicating 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 to1to include dynamic data likeUserName.