Hi, I have written a simple code to query database and return number of items in the http-functions.js file.
But I keep getting this error
{"error":{"name":"Error","errorGroup":"User","code":"WD_PERMISSION_DENIED","level":"warn"}}
Also, none of the console.log() statements are logging in the preview mode when i call the _functions-dev/… request.
Here’s the code snippet for the function
export function get_MyGoalsMails(request) {
let response = {
“headers”: {
“Content-Type”: “application/json”
}
};
console.log("Requested Category-"+request.path[0]);
return wixData.query(“User-Goals”)
.eq(“goalCategory”,request.path[0])
.find()
.then( (results) => {
console.log("No. of items-"+results.items.length);
response.body = {
“items”: results.items.length
};
if(results.items.length > 0)
return ok(response);
return notFound(response);
} )
.catch( (error) => {
response.body = {
“error”: error
};
return serverError(response);
} );
}
Make sure that you have your collection permissions set correctly. Also note that you won’t be able to see console.log() messages from the backend HTTP functions.
Take a look at the MyApi and MyApiClient example to see how to expose and access external APIs. The MyApiCombined app combines the API together with the consuming client, which makes debugging easier by allowing the display of console.log() diagnostic statements from both server and client to appear in the browser’s Javascript console.
Hey Yisrael,
Thanks for the tip. I noticed that the database I’m querying has read and write permissions set to members only. I would prefer to keep it that way.
So I was thinking instead of calling the wixData.query from the http-functions.js, what if I created a new backend module xyz.js with the query in it and called a function in the xyz.js (which returns just the item I need) from http-functions.js. Would that work?
Thanks
Hey Yisrael,
Thanks for the tip. I noticed that the database I’m querying has read and write permissions set to members only. I would prefer to keep it that way.
So I was thinking instead of calling the wixData.query from the http-functions.js, what if I created a new backend module xyz.js with the query in it and called a function in the xyz.js (which returns just the item I need) from http-functions.js. Would that work?
Thanks