parse-server: "Unable to connect to the Parse API" error thrown when trying to call a Cloud function with a Parse Query.

I have defined a Cloud function in main.js as below:

Parse.Cloud.define('getAllCurrentObs', function(request, response) {
    Parse.Cloud.useMasterKey();

    var queryObs = new Parse.Query("GCUR_OBSERVATION");
    queryObs.ascending("createdAt");
    queryObs.equalTo("ObservationStatus", 0);
    queryObs.limit(1000);

    queryObs.find().then(function(results) {
        response.success(results.length);
    }, function(error) {
        response.error("Error: " + error.code + " " + error.message);
    });
});

While trying the POST cURL command line to call the function, the command line prompt showed the following error message:

curl -X POST -H "X-Parse-Application-Id: APP_ID" -H "X-Parse-Master-Key: MASTER_KEY" -H "Content-Type: application/json" -d "{}" https://{MY_APP_NAME}.herokuapp.com/parse/functions/getAllCurrentObs {"code":141,"error":"Error: 100 XMLHttpRequest failed: \"Unable to connect to the Parse API\""}

The Heroku logs page showed: 2016-02-25T12:33:14.263956+00:00 heroku[router]: at=info method=POST path="/parse/functions/getAllCurrentObs" host={MY_APP_NAME}.herokuapp.com request_id=6af8cfa4-c935-4b52-a869-1d5dd47b93aa fwd="183.78.173.3" dyno=web.1 connect=0ms service=2764ms status=400 bytes=378

By the way, using cURL to post the default “hello” cloud function worked well.

Edit: I think the problem is any Parse Query made to a DB Class in a cloud function would fail.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 9
  • Comments: 16 (5 by maintainers)

Most upvoted comments

Just found the solution here: https://github.com/ParsePlatform/parse-server/issues/411

Just added: process.env.NODE_TLS_REJECT_UNAUTHORIZED = “0”;

in index.js, just before starting Parse Server:

var api = new ParseServer({...});

@grassland-curing-cfa did you set the serverURL in your parse server configuration?

Provide a serverURL option to the ParseServer call, something like:

var api = new ParseServer({
  databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID || 'myAppId',
  restAPIKey: process.env.REST_API_KEY || '',
  javascriptKey: process.env.JAVASCRIPT_KEY || '',
  serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse',
  masterKey: process.env.MASTER_KEY || '' //Add your master key here. Keep it secret!
});