Problem with -> Http function get table 'Members/PrivateMembersData'

Hello guys, I made a GET API from my wix site to powerbi to parse the data, I got all the tables I wanted, except the table ‘Members / PrivateMembersData’, I know i need to set the permissions for the function to work properly, the members table does not allow a custom usage setting like the others, is there any solution for this API to work?

Code I whrote below:


var allDatamembers = [];
var contagemmembers = null

//I changed the name of the function for security reasons
export async function get_getTables_Members(request) {
 let options = {
 "headers": {
 "Content-Type": "application/json"
        }
    };

 let table = 'Members/PrivateMembersData'

 // query a collection to find matching items
 wixData.query(table)
        .limit(1000)
        .find()
        .then((results) => {
 // matching items were found
 if (results.items.length === 0) {
 // no matching items found
 options.body = {
 "error": `No items was found`
                };
 return notFound(options);
            }

 let data = results.items
 allDatamembers.push(data)

 const countFirstQuery = results.length
 const countItems = results.totalCount
 
 //ciclos means how many querys it will have to do to get all items from the collection
 const ciclos = Math.ceil(Number(countItems / 1000))
 contagemmembers = ciclos

 for (let i = 1; i < ciclos; i++) {
 let toSkip = 1000 * i
 wixData.query(table)
                    .limit(1000)
                    .skip(toSkip)
                    .find()
                    .then((res) => {
 let data = res.items
 allDatamembers.push(data)
                    })
            }
        })
 // something went wrong
        .catch((error) => {
 options.body = {
 "error": error
            };
 return serverError(options);
        });

 var respostamembers = await pegarresultsmembers()

 options.body = {
 "items": respostamembers
    };
 return ok(options);
}
async function pegarresultsmembers() {
//wait the for to finish to return allData
 if (allDatamembers.length === contagemmembers) {
 return allDatamembers
    } else {
 await timeout(100)
 return pegarresultsmembers()
    }
}

function timeout(ms) {
 return new Promise(resp => {
 setTimeout(resp, ms)
    })
}
    

    
Thanks for the support!

I also tried setting up a scheduled job to copy the Members table, but it was not possible because it does not have the permission set.

You can try using suppressAuth. Maybe it’ll work:
https://www.wix.com/corvid/reference/wix-data.html#WixDataOptions

Got the same result

The code:


var allDatamembers = [];
var contagemmembers = null
//I changed the name of the function for security reasons
export async function get_getTables_Members(request) {
 let options = {
 "headers": {
 "Content-Type": "application/json"
        }
    };
        
    

 let table = 'Members/PrivateMembersData'

 let optionsquery = {
 "suppressAuth": true,
 "suppressHooks": true
      };

 // query a collection to find matching items
    wixData.query(table,optionsquery)
        .limit(1000)
        .find()
        .then((results) => {
 // matching items were found
 if (results.items.length === 0) {
 // no matching items found
 options.body = {
 "error": `No items was found`
                };
 return notFound(options);
            }

 let data = results.items
 allDatamembers.push(data)

 const countFirstQuery = results.length
 const countItems = results.totalCount
 
 //ciclos means how many querys it will have to do to get all items from the collection
 const ciclos = Math.ceil(Number(countItems / 1000))
 contagemmembers = ciclos

 for (let i = 1; i < ciclos; i++) {
 let toSkip = 1000 * i
 wixData.query(table)
                    .limit(1000)
                    .skip(toSkip)
                    .find()
                    .then((res) => {
 let data = res.items
 allDatamembers.push(data)
                    })
            }
        })
 // something went wrong
        .catch((error) => {
 options.body = {
 "error": error
            };
 return serverError(options);
        });

 var respostamembers = await pegarresultsmembers()

 options.body = {
 "items": respostamembers
    };
 return ok(options);
}
async function pegarresultsmembers() {
//wait the for to finish to return allData
 if (allDatamembers.length === contagemmembers) {
 return allDatamembers
    } else {
 await timeout(100)
 return pegarresultsmembers()
    }
}

function timeout(ms) {
 return new Promise(resp => {
 setTimeout(resp, ms)
    })
}
    

    
Thanks for the support!

https://support.wix.com/en/article/corvid-wix-members-privatemembersdata-collection-fields
You cannot change the PrivateMembersData collection permissions.

So as J. D. says earlier, if you have tried Wix Data Options and tried to suppress the permission checks and hooks from running and it still gives the same result etc, then there is nothing you can do about it.

@joaob , you put the options in the wrong place. It should be inside the find().
See here:
https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html#find

It works!!

THANKS A LOT !

You’re welcome :slight_smile: . Glad it worked.