Calling external API from Event Handler

Hi,
hope you are doing well.

Is it possible to call external API from event handler?
I am trying to call some 3rd party API to enrich response, but I am not able to from JS console.

Backendless.ServerCode.Persistence.afterFind('Property', async function(req, res) {
  return fetchAsync("https://jsonplaceholder.typicode.com/todos/1").then(evaluation => {
  console.log( "API CALL:" + evaluation );
  
  res.result
  });
});

async function fetchAsync (url) {
  const response = await fetch(url);
  const data = await response.json();
  return data;
}

I am getting an error SERVER_CODE | ERROR | [12960] ReferenceError: fetch is not defined at fetchAsync.

Is it possible to do it in other way or how can I import fetch?

Thanks a lot,
best,
Nick.

Hello @nike-teo!
Thank you for contacting us.

You can use Backendless.Request to solve your issue.

You can also find some good recommendations here: click

Regards,
Alexander

1 Like