Fetch result from function (backend only) is not passed to the calling function

Hello community,

I’ve been struggling with this for a few weeks now
I tried the public communitybut when you click Publish there, nothing happens so it’s broken
Called support , they cannot help
Created a ticket for velo team, after 8 days a reply that they cannot find the function I refer and don’t provide coding support

So as a last resort, I reach out here or I plan to leave Wix and take all my customers elsewhere as this is no longer very productive and actually frustrating.

I’ll try to properly describe the objective and my issue below

The goal:

  • call a backend function usig a cron job, this function will call another backend function to fetch a json object using the wix fetch API
  • return the result from the fetch to the calling function for further processing of the JSON object

The environment:

  • the function called by the cron is called astroPlus in backend/sailerLog.js
  • the function code looks like this
  • FYI I couldn’t post the actual url but it calls a public weather service
 export async function astroPlus() {

    console.log("Initiation : astroPlus () function to call API and retrieve JSON")
    //the endPoint
    let urlToFetch= "the link"
    await APICall(urlToFetch)
        .then((json) => console.log(json))
   //processing ... there is a lot more code below but it's not relevant for my post
  }
  • the called function APICall is conded as follows
// this is the function toquery the API 
export async function APICall(url) { 
    let result
    return fetch(url, { "method": "get" })
            .then(httpResponse => httpResponse.json())
            .then(json => {
                  return json;
        })
}

I also tried it like this

export async function APICall2(url) {
    //another try to fetch
    return await fetch(url, { "method": "get" })
        .then((httpResponse) => {
            if (httpResponse.ok) {
                return httpResponse.json()
            } else {
                return Promise.reject("Fetch failed")
            }
        })
}

The outcome:

  • both of the functions I pasted for APICall have the expected result, they return a JSON object
[backend/astroPlus.jsw, APICall2] called with (the link)
[backend/astroPlus.jsw, APICall2] returned with  {...}

The problem:

  • the calling function astroPlus never gets the result and I’ve tried a lot of different ways
    sync / async function
    chaining promises
    calling function by assigning to variable
  • I’m overlooking something here obviously but I’m stuck

Any help is appreciated :slight_smile:

Have a nice day

What results are you trying to call for? as I just call the databses i need in like 2 lines of code and that gives me anything i need passed?

I have never used a cron job. so i may be way off and in that wish i understood category. But if i can be of help i will? just a human learning too. willing to share what little knowledge i have
https://popperportal.wixsite.com/popperpinballclub/vpx-tables-1/ac-dc-(luci-premium)-(stern-2013) is where i am using allot of calls and drawers "multi-boxes) to organize data. then using data sent as a package to be received by the opening lightbox ReviewBox