Wix http functions not working but code is working

I can test the code in sandbox using a button on a page that calls the backend code that calls a remote rest service and loads images into the database. If i try launch it from the http function nothing happens (i get the successful response but the code doesnt actually run). I am not sure what to do since the code is all working and everything is published i have checked the database on live and all it good and have published the side again to ensure those scripts are updated.

Edit: confirmed it is the http function - if i use the button on the live site and use that to call the code from live it works. I need to have this automated to can someone help me understand why the http function isnt working?

by the way the response is fine when calling the function - is there a way i can access some logs to see what is going un?

here is the http function code (i have 3 other functions and they all working okay

export function get_chartdata(request) {

let options = {
“headers”: { “Content-Type”: “application/json” }
};

options.body = { "status": "ok" } 

pullecondata(); 

return ok(options);

};

here is the main function that does the work

export function pullecondata () {

//get url template
wixData.query(“charturl”)
.find()
.then( (results) => {
var item = results.items[0]
let urltemplate = item.urltemplate

//iterate rows to populate charts
wixData.query(“econdata”)
.find()
.then( (econresults) => {

        console.log(econresults.items.length) 

        econresults.items.forEach( **function** (element) { 

            console.log(element.release) 

let newitem = element
return fetch(newitem.data, {“method”: “get”})
.then( response => response.json())
.then(json => {
var labels =
var vals =

//access json data for chart from rest service payload
for(let i in json.dataset.data) {

var dt = new Date(json.dataset.data[i][0])
labels.push(dt.toLocaleDateString())
vals.push(json.dataset.data[i][1])

                } 

//remove some records not needed
vals.pop()
vals.pop()
vals.pop()
labels.pop()
labels.pop()
labels.pop()

//reorder for date
vals = vals.reverse()
labels = labels.reverse()

//build array list of labels and data
var quotedAndCommaSeparated = “'” + labels.join(“‘,’”) + “'”
var u = urltemplate.replace(‘£’, quotedAndCommaSeparated )
var g = u.replace( ‘@’,vals.join())

                newitem.chart = g 
                console.log("saving") 
                wixData.save("econdata", newitem); 

            }) 


        }) 


   }) 

}) 

}

Make sure you publish your site or the HTTP endpoints won’t be accessible. See the article Corvid: Exposing a Site API with HTTP Functions for more information on HTTP functions. You can also use the MyApi and MyApiClient example.

hi Yisrael

All is published several times and i have ensured the database collections are also in sync. The http function is returning a status okay but the code never runs. is it perhaps a permission issue i need to be aware of?

@waynetheron Hard to say what’s not working. It might be an issue of database permissions. Since this is backend code, you can use the suppressAuth option to eliminate that issue.

@yisrael-wix

Thank you Yisrael - suppressing auth worked :slight_smile: happy days

@waynetheron Wow! You mean I did something today? :beers::tada: