PrivateMembersData query returns Unknown Error

I have an app that requires my website user’s credentials for authentication, so I’ve tried querying the Members/PrivateMembersData collection. But my query only returns this error message in the Developer Console, which I’m assuming is a permission issue but can’t be sure.

Error Message in Console :
Unknown error. Request ID: 1568971261.58234844627221361. Message: Permission denied: {“message”:“permission_denied, details: {"RequiredRole":"Member","GivenIds":""}”,“details”:{“givenids”:“”,“requiredrole”:“Member”,“error”:“permission_denied”,“category”:“api_error”}}…

Here’s my code for your reference :

export function get_user() {
let options = {
“headers”: {
“Content-Type”: “application/json”
}
};

return wixData.query(“Members/PrivateMembersData”)
.find()
.then(results => {
if (results.items.length > 0) {
options.body ={
“items”: results.items
}
return ok(options);
}
})
}

Please let me know what am I doing wrong and what’s the right way to go about this. Thanks.

You might need to use Wix Data Options to have permission.
https://www.wix.com/corvid/reference/wix-data.html#WixDataOptions

https://support.wix.com/en/article/corvid-wix-members-privatemembersdata-collection-fields

To use the PrivateMembersData collection in code, refer to it as “Members/PrivateMembersData”.

wixData.query("Members/PrivateMembersData")
  .find()
  .then( (results) => {
    // handle the results
  } );

Take into account that the permissions for this collection are restricted. And a regular member can only read his/her own record. So you should limit the query to .eq(“_id”, userId)

Yes, I forgot to add that you can’t just use that given code as face value, you will need to add your equal to query otherwise you will possibly get errors still.

Thanks for adding that J. D. :grin:

Thank you so much for the response guys, I’ll give your tips a go. However, would it be advisable if I just created my own Members collection?

@woshiidaryl

Whatever works best for you.

You can look at this tutorial from Wix for a Members profile that creates another Members dataset.
https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area