Having trouble with a HTTP API call on a cloud function

The fault is clearly mine, but I am having trouble getting a response on an API call from a cloud function. I can’t even get an error logged in the console. . . My code is as follows, does anyone have any suggestions? Thanks very much!

Moralis.Cloud.define("getToolModifierItems", async (request) => {
    const results = "";
      url: 'https://api.lunarcrush.com/v2?data=global&key=796rfpotk3eh4690c0zzlh'
    }).then(function(httpResponse) {
      // success
      results = (httpResponse.text);
    },function(httpResponse) {
      // error
      console.error('Request failed with response code ' + httpResponse.status);
  return results;

Learn about logger in order to print messages to the console: https://docs.moralis.io/moralis-server/cloud-functions#console-log

1 Like

Thanks for the quick reply, and the link. I have learnt about logging and now have that working great. I still can’t get the API call to drop into either success or error on call though, it’s like it’s failing silently. I can’t see any issues in the code, but am clearly doing something wrong. I copied the code directly from the documentation - does anything in my code block look wrong to you?

Thanks very much

Ah, I needed to follow the redirect! Thanks again.

1 Like

Ok great that it works

Yes, thanks. I thought I had checked for that, was kicking myself when I found it :rofl:

1 Like