Add members to a group
This example demonstrates how to add one or more members to an existing group in ONLYOFFICE DocSpace using the API. Optionally, you can rename the group and assign a new manager in the same request.
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
// Config
const API_HOST = 'https://yourportal.onlyoffice.com';
const API_KEY = 'your_api_key';
// Headers with API key
const HEADERS = {
Authorization: API_KEY,
'Content-Type': 'application/json',
};
// Step 1: Add members to a group (optionally rename and/or change manager)
async function addMembersToGroup(groupId, members, newName = null, newManager = null) {
const url = `${API_HOST}/api/2.0/group/${groupId}`;
const data = { membersToAdd: members };
if (newName) data.groupName = newName;
if (newManager) data.groupManager = newManager;
const res = await fetch(url, {
method: 'PUT',
headers: HEADERS,
body: JSON.stringify(data),
});
if (!res.ok) {
const text = await res.text();
console.log(`Group update failed. Status code: ${res.status}, Message: ${text}`);
return;
}
console.log(`Members added to group ${groupId}: ${JSON.stringify(members)}`);
if (newName) console.log(`Group renamed to: ${newName}`);
if (newManager) console.log(`New manager assigned: ${newManager}`);
}
// Run the method
(async () => {
await addMembersToGroup(
'c652dba3-210e-436d-b264-df5ceda0a48e', // Replace with your group ID
['d9be1cab-3ab4-4012-ad60-48218b2713dc', '4c65a238-ca50-4374-b904-0d51d4c1822b'], // Member UUIDs
'Project Alpha Team',
'c652dba3-210e-436d-b264-df5ceda0a48e'
);
})();
import requests
# Set your DocSpace portal URL and API key
API_HOST = 'https://yourportal.onlyoffice.com'
API_KEY = 'your_api_key'
# Headers with API key
headers = {
'Authorization': API_KEY,
'Content-Type': 'application/json'
}
# Step 1: Add members to a group (optionally rename and/or change manager)
def add_members_to_group(group_id, members, new_name=None, new_manager=None):
url = f"{API_HOST}/api/2.0/group/{group_id}"
data = {
'membersToAdd': members
}
if new_name:
data['groupName'] = new_name
if new_manager:
data['groupManager'] = new_manager
response = requests.put(url, json=data, headers=headers)
if response.status_code == 200:
print(f"Members added to group {group_id}: {members}")
if new_name:
print(f"Group renamed to: {new_name}")
if new_manager:
print(f"New manager assigned: {new_manager}")
else:
print(f"Group update failed. Status code: {response.status_code}, Message: {response.text}")
# Run the method
if __name__ == '__main__':
add_members_to_group(
'c652dba3-210e-436d-b264-df5ceda0a48e', # Replace with your group ID
['d9be1cab-3ab4-4012-ad60-48218b2713dc', '4c65a238-ca50-4374-b904-0d51d4c1822b'], # Member UUIDs
new_name="Project Alpha Team",
new_manager='c652dba3-210e-436d-b264-df5ceda0a48e'
)
How it works
A PUT request is sent to /api/2.0/group/:id with the following payload:
membersToAdd: Array of user UUIDs to add to the group.groupName(optional): New display name for the group.groupManager(optional): UUID of the new manager.
If the request is successful, the API returns the updated group details and applies all provided changes in a single operation.