Search code examples
parse-platformparse-cloud-codeback4app

How to make a http request with axios from inside Parse Cloud Code function?


I'm trying to make a request from inside a Parse Cloud Code function. My attempt looks likes this:

const axios = require('axios').default;

Parse.Cloud.define("loginSchool", async (request) => {
  test = await axios({
    method: 'get',
    url: 'https://google.com'
  });
  return(test);
});

I can call the function via curl but it only returns Bad Gateway as result.

I'm using Back4App with Parse Version 5.2.3.

What is the correct way to use axios inside a cloud code function for making a http request?


Solution

  • Found the problem by myself but maybe it helps someone else.

    axios is not included as dependency by default inside parse cloud code. Therefore you need to install it. e.g. if you develop locally run npm install axios in the cloud folder and afterwards deploy the cloud folder, including the node_modules folder.

    Alternativly I imagine you could download the axios module and upload it via the Dashboard for Cloud Code. But for me setting up a local parse_server helped me a lot because I could see the logs more quickly and therefore determine the problem.