Skip to main content

Get Groups

This section covers operations to retrieve and query node groups. These operations are performed using the ESPRMUser instance.

note

To get the user instance, use ESPRMAuth.getLoggedInUser method:

try {
const authInstance = ESPRMBase.getAuthInstance();
const userInstance = await authInstance.getLoggedInUser();

if (userInstance) {
// Use userInstance for group operations
} else {
console.log("No user is currently logged in");
}
} catch (error) {
console.error("Error getting logged in user:", error);
}

Get User Groups

To retrieve user groups, use the getGroups method. This method supports pagination to fetch groups in batches.

const requestParams = {
resultCount: 10,
withNodeList: true,
withSubGroups: true
};

try {
let allNodeGroups = [];
let response = await userInstance.getGroups(requestParams);

allNodeGroups = allNodeGroups.concat(response.groups);

while (response.hasNext) {
response = await response.fetchNext();
allNodeGroups = allNodeGroups.concat(response.groups);
}

console.log("All node groups:", allNodeGroups);
} catch (error) {
console.error("Error getting node groups:", error);
}

Get Group By ID

To retrieve a specific group by its ID, use the getGroupById method.

try {
const group = await userInstance.getGroupById({
groupId: "group_id_123"
});
console.log("Group details:", group);
} catch (error) {
console.error("Error getting group by ID:", error);
}

Get Group By Name

To retrieve a specific group by its name, use the getGroupByName method.

try {
const group = await userInstance.getGroupByName({
groupName: "Living Room Devices"
});
console.log("Group details:", group);
} catch (error) {
console.error("Error getting group by name:", error);
}

On this page