Having trouble with cloud function

Not sure what I’m doing wrong currently returns nothing when should return a json string also not showing input in logs

Moralis.Cloud.define("getMeta", async (request,uri) => {
  const logger = Moralis.Cloud.getLogger();
let results; 
results = await Moralis.Cloud.httpRequest({
  url: 'https://defi-city.com/api/city/463',
    followRedirects: true,
  headers: {
    'Content-Type': 'application/json;charset=utf-8'
  }
}).then(function(httpResponse) {
    results=httpResponse.text;
    logger.info("over here"+results);
    logger.info(httpResponse.text);
}, function(httpResponse) {
  logger.info('Request failed with response code ' + httpResponse.status);
});
  logger.info("end"+results);
  return await results;
});
let mData = await Moralis.Cloud.run("getMeta",uri);
1 Like

Hey @PeacanDuck

Your callback function doesn’t return anything, that’s why you have []

Just add return results into the callback:

Moralis.Cloud.define("getMeta", async (request, uri) => {
  const logger = Moralis.Cloud.getLogger();
  let results;
  results = await Moralis.Cloud.httpRequest({
    url: "https://defi-city.com/api/city/463",
    followRedirects: true,
    headers: {
      "Content-Type": "application/json;charset=utf-8",
    },
  }).then(
    function (httpResponse) {
      results = httpResponse.text;
      logger.info("over here" + results);
      logger.info(httpResponse.text);
      return results; //There
    }
  );
  logger.info("end" + results);
  return results;
});

thanks got it working

1 Like

Awesome!

Happy BUIDLing :man_factory_worker: