I read and applied all the related problems here but could not solve the basic wix data examples to work. I am on this issue for several days and I think I need a help now.
I have http-functions.js and DataService.jsw files and trying to create a an api get endpoint with those.
http-functions.js has this code:
import {ok, notFound, serverError} from ‘wix-http-functions’;
import wixData from ‘wix-data’;
import {get_result} from ‘backend/DataService’;
export function get_myFunction(request) {
let options = {
“headers”: {
“Content-Type”: “application/json”
}
};
let resultshere = get_result(“1”);
options.body = resultshere.items; return ok(options);
DataService.jsw has this code:
import wixData from ‘wix-data’;
import {ok, notFound, serverError} from ‘wix-http-functions’;
By the way, all the collection permissions are set to anyone.
When i tested in more detail, I have concluded that, wixData.query is working on the frontside (when it is under onReady function). But in the backend files like http-functions.js or DataService.jsw, this mechanism does not work.
The link is the real link that I am working on it. I have to solve the issue immediately.
It looks like that I have the same problem.
When I try to perform a query with any of our collections, I receive an error.
The error object is an empty ({}) object.
The problem raised, when I tried to query a custom access collection. I have changed it such that it is permitted it to anyone (just for the tests). I still receive the same error in the query. Also when I tried other permissions levels I receive the same problem.
I wonder did you find the problem in your code?
Maybe I have the same problem.
Steps to debug:
1 - Query collection in a page code
wixData.query('collection).find().then(res => {console.log(‘Results’, res) })
2 - Put the working query in the HTTP js file, preview the site and open the endpoint GET from another browser tab using the DEV function path:
(Publish the site before preview)
/_functions-dev/
The preview console will show the log.
FYI:
_function-dev/getfunction => preview mode (show console.log),
_function/getfuntion => live
If no log, the browser is using OPTION to pre-flight and/or you need to reply (send a response) with “Accept”: “application/json” and some “Allow…” headers.
By security, the Browser allows request with no cors checking for application/x-www-form-urlencoded, multipart/form-data, text/plain “Content-Type”.
Read the Velo doc and the mozilla docs about HTTP cors and HTTP headers.
Please add your own issue into a new post instead of bumping up an old post. Explain what you are trying to do, what works, and what doesn’t. Also, add any code in a code block as stated in the Forum Guidelines .