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!
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!
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.