0

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?

Sven
  • 1,648
  • 1
  • 21
  • 31
  • Have you already checked this guide https://docs.parseplatform.org/cloudcode/guide/#networking? It can help you with HTTP requests – Charles Mar 07 '23 at 01:27
  • Thanks for your help. Yes using the requests would work, but the documentation mentions that it will be deprecated in the next release, therefore I wanted to use a different module. – Sven Mar 12 '23 at 17:50

1 Answers1

0

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.

Sven
  • 1,648
  • 1
  • 21
  • 31