Skip to main content

Get a group with members

This example demonstrates how to retrieve a group by ID in ONLYOFFICE DocSpace and include its members in the response.

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';
const GROUP_ID = '08e455dc-98c4-4390-b36f-54757080149c'; // Replace with your actual group ID

// Headers with API key
const headers = {
Authorization: API_KEY,
};

// Step 1: Get group by ID with members included
function getGroupWithMembers(groupId) {
const params = new URLSearchParams({ includeMembers: 'True' });
const url = `${API_HOST}/api/2.0/group/${groupId}?${params.toString()}`;

return fetch(url, { method: 'GET', headers })
.then((res) => {
if (res.status === 200) return res.json();
return res.text().then((t) => {
console.log(`Group retrieval failed. Status code: ${res.status}, Message: ${t}`);
return null;
});
})
.then((data) => {
const group = data?.response || {};
console.log(`Group: ${group.name}`);
console.log('Members:');
(group.members || []).forEach((m) => {
console.log(`- ${m.id}${m.displayName}`);
});
return group;
})
.catch((err) => {
console.log(`Group retrieval error: ${err.message}`);
return null;
});
}

// Run the method
console.log('Getting group with members...');
getGroupWithMembers(GROUP_ID);

How it works

A GET request is sent to /api/2.0/group/:id with the following query parameter:

  • includeMembers: true — include the list of group members in the response.

If successful, the API returns group details such as:

  • name — group display name
  • members — array of member objects, each containing:
    • id — unique member identifier (UUID)
    • displayName — full name of the member