Permissions in webMethod for Members Query Builder not working?

I try to create a dynamic map of members locations. Of course only of them which have a public profile. So I created a backend function in file.web.js with permissions.Anyone.

But the result is always:
privacyStatus:“UNKNOWN”
activityStatus:“UNKNOWN”

As far as I understand, it should by PRIVAT or PUBLIC.
What’s wrong, my understanding, the code or is there a bug?

Thanks for help

Code in backend:
import { members } from “wix-members.v2”;
import { Permissions, webMethod } from “wix-web-module”;

export const myQueryMembersFunction = webMethod(
Permissions.Anyone,
async (options) => {
try {
const siteMembers = await members.queryMembers(options)
.eq(“profile.slug”,(“someSlug”))
.limit(countMembers.totalCount)
.find();
console.log(“Retrieved members:”, siteMembers.items);
return siteMembers;
} catch (error) {
console.error(error);
// Handle the error
}
},
);

Hello,

You need to change the fieldset options array to “EXTENDED” to show privacy and activity status. You also need to add “profile.slug” in the fields array since its default is the nickname. Here’s the docs for reference.

Try this sample code:

import { members } from "wix-members.v2";
import { webMethod, Permissions } from "wix-web-module";

/* Sample parameter values
 * {
 *   "options": {
 *       "fieldsets": ["EXTENDED"],
 *       "search": {
 *           "expression": "John Doe"
 *       },
 *       "fields": [
 *           "loginEmail",
 *           "contact.firstName",
 *           "contact.lastName",
 *           "profile.title",
 *           "profile.nickname",
 *           "profile.slug"
 *       ]
 *   }
 * }
 */

const defaultOptions = {
    options: {
        fieldsets: ['EXTENDED'],
        "fields": [
            "loginEmail",
            "contact.firstName",
            "contact.lastName",
            "profile.title",
            "profile.nickname",
            "profile.slug"
        ]
    }
}

export const myQueryMembersFunction = webMethod(Permissions.Anyone, async (options) => {
    let optionsToUse = options
    if (!optionsToUse) optionsToUse = defaultOptions // in case you are passing options dynamically or not
    try {
        const siteMembers = await members.queryMembers(optionsToUse).find();
        console.log("Retrieved members:", siteMembers);

        return siteMembers;
    } catch (error) {
        console.error(error);
        // Handle the error
    }
},
);

Hello and thanks for the very quick answer. Unfortunately it doesn’t work.
I always get privacyStatus:“UNKNOWN”, the options list ist filled as in the example.
I replaced in your code the single quotes by double quotes as reported in the mentioned documentation.

Thanks a lot.

const defaultOptions = {
options: {
fieldsets: [“EXTENDED”],
fields: [
“loginEmail”,
“contact.firstName”,
“contact.lastName”,
“profile.title”,
“profile.nickname”,
“profile.slug”
]
}
}

export const myQueryMembersFunction = webMethod(Permissions.Anyone, async (options) => {
let optionsToUse = options
if (!optionsToUse) optionsToUse = defaultOptions
console.log(“optionsToUse”, optionsToUse)
try {
const siteMembers = await members.queryMembers(optionsToUse).find();
console.log(“Retrieved members:”, siteMembers);
return siteMembers;
} catch (error) {
console.error(error);
// Handle the error
}
},
);

Got it, so I put it in a test site and was able to get it to work. You just have to update the default options and remove the additional nested “options” inside the object. (Docs were misleading there.) This code should work for you. You just need to add your query filters as well. Also be careful with the limit- I believe 100 is the max limit for this query so if you need more than 100 you need to loop it until hasNext is false.

My test code

import { members } from "wix-members.v2";
import { webMethod, Permissions } from "wix-web-module";

const defaultOptions = {
    fieldsets: ['EXTENDED'],
    fields: [
        "loginEmail",
        "contact.firstName",
        "contact.lastName",
        "profile.title",
        "profile.nickname",
        "profile.slug"
    ]
}

export const myQueryMembersFunction = webMethod(Permissions.Anyone, async (options) => {
    const optionsToUse = options ? options : defaultOptions

    try {
        const siteMembers = await members.queryMembers(optionsToUse).find();
        console.log("Retrieved members:", siteMembers);

        return siteMembers;
    } catch (error) {
        console.error(error);
        // Handle the error
    }
}, );

The code resolved the “UNKNOWN” references from my tests.

Hello
I don’t know why, but with your test code it’s working now. Also thanks for your tip about the maximum numbers of retreivable members. I’ll have look on it.
Regards