Realm Function axios call never waits despite HTTP request seemingly finishing

I have encountered a very strange issue on a realm function. My function uses the latest axios library to make a POST request to another server. On that server, I know that the request is completing successfully. I have had to add log statements right before the response gets sent, and I can see those statements being logged, so I know the request is successful and being sent back to the realm function context. Also, when testing in postman, this same POST request succeeds no problem. So I KNOW the axios call should resolve. However, it does not resolve. Below is the function code making the call:

const url = context.values.get("secret_url") + "/endpoint";
  const data = {
    number_recommendations: 400,
    interests: profile,
    price_min: price_min || 10,
    price_max: price_max || 500,
  };
  const config = {
    method: "post",
    url,
    headers: {
      "Content-Type": "application/json",
    },
    data,
  };

  const recommendationsRequest = await axios(config); 

I’ve tried logging and nothing happens after the axios await.

Anybody had similar issues? Seems like a bug with realm perhaps.

Hi @Lukas_deConantseszn1,

I’ve never used this module on Realm.

To send http calls from functions you should use context.http:

Please try the following according to syntax and example.

Thanks
Pavel

Hi Lukas, is it possible that this is due to the API that you are using? The following worked for me and returned a request payload:

exports = async function(arg) {
var axios = require('axios');
try {
        const resp = await axios.get('https://api.url......&apiKey=<api_key>');
        console.log(resp.data[0]); 
    } catch (err) {
        console.error(err);
    }
};

(This is with Axios 0.19.2)

@Pavel_Duchovny I might try using the http.context.post then.

@Sumedha_Mehta1 thanks for trying out axios. I wouldn’t doubt that it worked for you, it used to work for me and it honestly has stopped working for no clear reason. So I feel the possible bug would be hard to reproduce in nature. Not very helpful I know :frowning: