For control reasons, I have to produce a list of all members and their assigned roles.
Accessing the list of members is done (through a wixData.query(“Members/FullData”) request. for each member, I would like to get their roles.
That is my problem : I found a getroles() fonction, but it is only active for the currently logged member. SO I am looking for something like a function accepting a memberID as parameter, and may be some options getroles(ID) , but could not find it in the diffrents members API (font-end, back-end, V2)
Code used at the page level is :
wixData.query(“Members/FullData”)
.find()
.then((results) => {
// handle the results
for (let i = 0; i < results.length; i++) {
console.log(results.items[i]._id);
console.log(results.items[i].loginEmail);
console.log(results.items[i].activityStatus);
console.log(results.items[i].status);
console.log(results.items[i].lastLoginDate);
// there I have the id of member i
// and I want to extract the roles he has
… what can I do ???
}
});
You can use listMemberships to get the roles for a given memberId
.
It seems to be the right way, but when I run it I got an error that I am not sure to understand (may be linked to a licence problem, this site is a free one, but getting the members list with
import { members } from ‘wix-members.v2’;
works well ?)
Error: message: groups application is not provisioned for meta site `a13cf789-d728-46d2-9045-4c4636b7b610`
details:
applicationError:
description: Precondition Required
code: PRECONDITION_REQUIRED
data: {}
This is the code I call with the memberId
GetRoles4User(memberId);
async function GetRoles4User(memberId) {
console.log("eNtry roles")
let options = {
limit: 100
};
try {
const result = await wixGroupsV2.members.listMemberships(memberId, options);
console.log(result);
//return result;
} catch (error) {
console.error(error);
// Handle the error
}
}
I also tested with the id of one member, same result.
Apologies. I misunderstood the docs. This function is for Wix Groups which is a separate Wix App and not for Wix Members.
I’m checking to see what other options there are.
So looks like in the case of Wix Members, Groups and Roles are the same so the solution described previously will work but you just need to also add the Wix Groups app to your site: Wix Groups: Adding and Setting Up Wix Groups | Help Center | Wix.com