跳到主要内容

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

  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
// 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'
);
})();

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.