Skip to main content

Remove members from a group

This example demonstrates how to remove one or more members from a group in ONLYOFFICE DocSpace using the API.

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 your DocSpace portal URL and API key
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: Remove members from a group
async function removeGroupMembers(groupId, members) {
const url = `${API_HOST}/api/2.0/group/${groupId}/members`;
const res = await fetch(url, {
method: 'DELETE',
headers: HEADERS,
body: JSON.stringify({ members }),
});

if (!res.ok) {
const text = await res.text();
console.log(`Remove members failed. Status code: ${res.status}, Message: ${text}`);
return;
}

console.log(`Members removed from group ${groupId}: ${JSON.stringify(members)}`);
}

// Run the method
(async () => {
try {
console.log('Removing members from the group...');
await removeGroupMembers(
'c652dba3-210e-436d-b264-df5ceda0a48e', // Replace with your group ID
['4c65a238-ca50-4374-b904-0d51d4c1822b'] // Replace with member IDs to remove
);
} catch (err) {
console.log(`Remove members error: ${err.message}`);
}
})();

How it works

A DELETE request is sent to /api/2.0/group/:id/members with the following payload:

  • members: An array of user UUIDs to remove from the group.

If successful, the API confirms removal (HTTP 200). Depending on configuration, the response may include updated group information or a boolean response: true.