Retrieving data from wix

@amandam , do you have any advice for Cue in regard to how to investigate/handle this problem?

@jonatandor35 Happy to attempt! Looks like you’ve already provided some good advice. Thank you as always

@chidiejike Hello. I read through this thread and I can’t promise I can help, but happy to take a look. Can you provide the following:

Links to both sites (the one exposing the data and the one receiving)
Tell me which files/pages in each site have the relevant code.
How is the GET request triggered
When you say it doesn’t work, what are the errors or other messages you are receiving?

I want users to GET information from my website to an api or extension added by users on their website or an HTML page. The URL resource is my wix website trackimize.com. The GET request is in an HTML extention in a browser or api widget meant to send a request from any HTML page or webpage of any site to my wix site.

Get request

const Http = new XMLHttpRequest();const url="https://trackimize.com/_functions/myFunction/totalEntries";
Http.open("GET", url);
Http.setRequestHeader("Accept", 'application/json');
Http.send();
Http.onreadystatechange = (e) => {
console.log((JSON.parse(Http.responseText)).items)if((JSON.parse(Http.responseText)).items!==1){
document.getElementById("total").innerHTML=(JSON.parse(Http.responseText)).items

}else if((JSON.parse(Http.responseText)).items===1){
document.getElementById("total").innerHTML=window.companyName}return ((JSON.parse(Http.responseText)).items)}}

in the wix backend .jsw code

export function get_myFunction(request) {if(request.path[0]==="totalEntries"){let options = {"headers": {"Access-Control-Allow-Methods": "OPTIONS,GET,HEAD,PUT,PATCH,POST,DELETE","Content-Type": "application/json","Access-Control-Allow-Origin": "*","x-requested-with": "XMLHttpRequest","Connection": "keep-alive","Access-Control-Allow-Headers": "Content-Type, Accept"}};return wixData.query("TOTAL").eq("name",request.path[0]).find().then( (results) => {if(results.items.length > 0) {options.body = {"items": results.items[0].total};return ok(options)}}

all of the above does not work

I decided to disable my browser security due to CORS. This is the error I get after disabling the browser security

Uncaught SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at XMLHttpRequest.Http.onreadystatechange

In other words, wix is not sending anything to my calling code.

@chidiejike I am not sure what is going on. I did visit your site, but was not able to clearly tell where to go to see this functionality in action to assist with debugging. I do not think I personally will be able to assist you in this case but perhaps someone from the community will understand the use case better than I do. You can also look to the marketplace if you would like to hire a developer to work on this issue for you.

If you believe it is a bug versus some issue with the code, you must report that through the steps listed here: How to report a bug

@amandam To see how it works, all you need to do is to add the GET request to an HTML page to see if my site sends any information back or you can add it to the browser developer console.

These are the errors I see when testing in postman. Again, I’m not the best resource to assist you in debugging what’s going on here. But here’s a place to start perhaps

@amandam if wix can reproduce same on their website then that will determine if the problem is peculiar to my site or a general bug in wix.

@chidiejike This forum is not for customer support, it is a community driven space for users to help each other work through coding issues. If you think this is potentially an issue with something in wix in general (i.e. a bug) you will need to report that through the steps listed here: How to report a bug

@amandam On a similar cross platform issue, were you able to make onesignal work? I was able to send a code from the developer console in the browser of my website’s webpage to update tags, ids etc in my onesignal account but when same code is added to a wix html iframe it does not work.

@chidiejike I have not personally integrated one signal, however when using the html iframe element, the iframe is actually wrapped in another iframe so I’m not sure if an implementation using that method would work or not. I would perhaps start a new thread asking if anyone here in the community has worked with One Signal specifically wrapped in an iframe element. If I come across any resources I will share them as well.