Parse-server: Query in Parse Cloud returns "unauthorized" error

Created on 11 Feb 2016  Â·  67Comments  Â·  Source: parse-community/parse-server

The command query.find always returns error in Parse Cloud. The response is Response Body : {"code":141,"error":"Error: undefined unauthorized"}.
The request is being done by Swift SDK.
It looks that Parse Cloud can't access the classes of Parse Server.

What could be possible reasons ?

Parse.Cloud.beforeSave("Message", function(request, response) {
    if (!request.object.get("uniqueCode")) {
        response.error('A Message must have a uniqueCode.');
    } else {
        var Message = Parse.Object.extend("Message");
        var query = new Parse.Query(Message);
        query.equalTo("uniqueCode", request.object.get("uniqueCode"));
        query.find({
            success: function(results) {
                if (results.length > 0) {
                    response.success();
                } else {
                    response.error("A Message with this uniqueCode already exists.");
                }
            },
            error: function(error) {
                response.error("Error: " + error.code + " " + error.message);
            }
        });
    }
});
troubleshooting

Most helpful comment

Are you setting any client keys in the ParseServer initialization? (rest, js, client, dotnet)... If so, remove them.

All 67 comments

Are you requiring/defining Parse in your cloud code file? This should not be done, as it is a global we mutate during ParseServer initialization.

No, I am not. The code above is exactly the cloud/main.js file.

Are you setting any client keys in the ParseServer initialization? (rest, js, client, dotnet)... If so, remove them.

My settings is according to the Parse Server example:
It is hosted in Heroku and the env vars below are configured.

var databaseUri = process.env.DATABASE_URI || process.env.MONGOLAB_URI;

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',
  masterKey: process.env.MASTER_KEY || '',
  clientKey: process.env.CLIENT_KEY || ''
});

If I remove the keys ( var api = new ParseServer() ), will the server still work and will it be able to be accessed by mobile SDK ???
The request to insert a new message (that triggers the beforeSave()) is done by Swift SDK.

I think I have the same problem as @leo-one. I can't use any queries in cloud code using the parse server as they return with the error {"code":141,"error":"Error: undefined unauthorized"}.

When diving into the source to troubleshoot I saw that all the queries (find, first, get etc) results in node_modules/parse-server/node_modules/parse/lib/node/RESTController.js:ajax() sending a post request to https://api.parse.com/1/classes/MyObject which of course will result in unauthorized as parse doesn't know anything about my local app. I tried sending a get request to http://localhost:1337/parse/classes/MyObject which works and returns objects as expected.

I'm probably missing something here, but what would you have to do to get queries working in cloud code with a local parse server?

What I missed was the serverURL option. Is it the same for you @leo-one? For me the following works perfectly for local development:

app.use('/parse', new ParseServer({
    databaseURI: process.env.MONGOLAB_URI || 'mongodb://localhost:27017/myApp',
    cloud: __dirname + '/cloud/main.js',
    appId: 'myAppId',
    masterKey: 'tmp_master_key',
    serverURL: 'http://localhost:1337/parse'
}));

@simonbengtsson Just out of curiosity, what is the hosting solution are you using ?

I am using Heroku and I tried:
serverURL: 'https://localhost:1337/parse' or
serverURL: 'http://localhost:1337/parse' or serverURL: 'https://localhost:' + port + '/parse'-> received {"code":141,"error":"Error: 100 XMLHttpRequest failed: \"Unable to connect to the Parse API\""}

serverURL: 'http://localhost:' + port + '/parse'-> received {"code":141,"error":"Error: undefined unauthorized"}

None of above ones worked.

I've written the command line:

Parse.Cloud.beforeSave("Message", function(request, response) {
    console.log('Parse.serverURL: ' + Parse.serverURL);
    if (!request.object.get("uniqueCode")) {
    //more code

and it printed app[web.1]: Parse.serverURL: http://localhost:30835/parse in Heroku as expected.

What more could be wrong ?

Im using the parse server locally. The serverurl for heroku would be something like http://your-heroku-app-id.herokuapp.com/parse. Or simply where the parse server is located.

Along with setting the serverURL in index.js make sure you are also passing a valid sessionToken otherwise it will throw an unauthorized error.

Also getting a similar response (141 / unauthorised) via Cloud Code. App ID matches client-side and in the ParseServer constructor + client keys not defined in client/server. Locally regular CloudCode functions (like the default hello function in parse-server-example) work just fine, it seems to be queries that have issues. Both all fail when deployed to heroku.

client side JS:

Parse.initialize("the_app_id", ""); 
Parse.serverURL = "/parse";
...
Parse.Cloud.run("validateEmail", {email:"..."}, {});
...

=>

cloud/main.js:

Parse.Cloud.define('validateEmail', function(req, res) {

    // Get the email address of the user we are going to check
    var email = req.params.email;

    // Execute query with Parse
    var query = new Parse.Query("ObjectTest");
    query.equalTo('email', email);
    query.find({
        success: function(result) {
            res.success(result);
        },
        error: function(err) {
            res.error(err);
        }
    });
});

(nothing declared outside of Parse.Cloud.define, Parse not re-imported etc)

=> {"code":141,"error":{"message":"unauthorized"}}

What is your initialization code for the parse server @jamiechapman? Make sure you are using the serverURL option there as well.

@simonbengtsson

The serverURL is defined and matches that defined by the client. I have tried fully qualified URL's in the client-side (http://www etc) and a relative path, both produce error 141 for some odd reason!

var api = new ParseServer({
    databaseURI: databaseUri || 'mongodb://XXXXXXX',
    cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
    appId: process.env.APP_ID || 'XXXXXXX',
    masterKey: process.env.MASTER_KEY || 'XXXXXXX',
    clientKey: process.env.CLIENT_KEY || '',
    serverURL: 'http://www.XXXXXXX.com/parse'
});

(XXXXXXX's subbed in place of real values, both match server/client side)

@simonbengtsson Think I sussed it! The environment variable APP_ID had an extra character at the end which likely caused the requests to (rightly) fail. Thanks for the help! :+1:

In my case, I have no clues about what's happening yet.
I tried 'https://localhost:' + port + '/parse' and 'https://www.XXXXXXX.com/parse' (using domain name).
I recreated the session token but with no effect too.
My APP_ID is correct and it is the same used in Swift and Android clients.

I do not know how to debug it. There is no additional information.
My files have the same structure as parse-example, with no modifications. The unique difference is an additional FACEBOOK_APP_ID env var (nothing related to code).
Everything works well except the Parse Cloud.

My solution, at moment, is an instance of a custom Express app (connected to the same database of the Parse Server) that handles manually the requests that would have been handled by the triggers.

Can you share the, preferably simplified, code you are using @leo-one? What do you mean with custom express app? Can you use queries in the same express app used by the parse server?

@simonbengtsson the code is simple, almost equals to Parser Server example in github page.
I am using parser-server 2.0.8 version.
See below:

index.js

var express = require('express');
var ParseServer = require('parse-server').ParseServer;

var databaseUri = process.env.DATABASE_URI || process.env.MONGOLAB_URI;

if (!databaseUri) {
  console.log('DATABASE_URI not specified, falling back to localhost.');
}

var app = express();

var port = process.env.PORT || 1337;

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',
  masterKey: process.env.MASTER_KEY || '',
  clientKey: process.env.CLIENT_KEY || '',
  serverURL: 'http://localhost:' + port + '/parse'
});


// Serve the Parse API on the /parse URL prefix
app.use('/parse', api);

app.get('/', function(req, res) {
  res.status(200).send('Express is running here.');
});


app.listen(port, function() {
    console.log('parse-server-example running on port ' + port + '.');
});

cloud/main.js

Parse.Cloud.define('hello', function(req, res) {
  res.success('Hi'); // it works
});

Parse.Cloud.beforeSave("Message", function(request, response) {

        // it prints http://localhost:29257/parse as expected
    console.log('Parse.serverURL: ' + Parse.serverURL);

    var query = new Parse.Query("Message");
    query.equalTo("uniqueCode", request.object.get("uniqueCode"));
    query.find({
        success: function(results) {
            if (results.length > 0) {
                response.success();
            } else {
                response.error("A Message with this uniqueCode already exists.");
            }
        },
        error: function(error) {
            response.error("Error: " + error.code + " " + error.message);
        }
    });
});

In iOS Swift app

let message = PFObject(className:"Message")
message["content"] = "Hello World"
message["toId"] = userId
message["fromId"] = PFUser.currentUser()!.objectId!
message["uniqueCode"] = "ITSREALLYUNIQUE"
message.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in
            if let error = error {
                print(error.debugDescription) 
                // it prints Response Body : {"code":141,"error":"Error: undefined unauthorized"} 
            }
            print("success: \(success)")
}

I think the following issue is similar. I will check it later: https://github.com/ParsePlatform/parse-server/issues/407

@simonbengtsson Yes. You can create another Node.js/Express server and point it to the same database that Parse Server uses. Then you can execute your custom queries and operations.
At moment, I am building the message system isolated from Parser Server (but using same database) until this issue is solved.

I tried your code and for me it works, I used the rest api though. Does it work if you use curl instead? Do your ios app have the correct serverURL?

curl -X PUT -H "X-Parse-Application-Id: myAppId" -H "X-Parse-Master-Key: _master_key_" -d '{"content": "Hello World"}' http://localhost: 29257/parse/classes/Message/_objectId_

@simonbengtsson Thanks, but I execute the same curl command that you posted and I received the same error {"code":141,"error":"Error: undefined unauthorized"} .
Yes. My iOS app has the correct server url, because everything works well except if the class operation has a trigger.

This is the code:

        let config = ParseClientConfiguration(block: {
            (ParseMutableClientConfiguration) -> Void in

            ParseMutableClientConfiguration.applicationId = "APP_ID";
            ParseMutableClientConfiguration.clientKey = "CLIENT_KEY";
            ParseMutableClientConfiguration.server = "https://nameofapp.herokuapp.com/parse";
        });

        Parse.initializeWithConfiguration(config);

I noted that all tests that were posted here were in localhost. Maybe can it be a Heroku problem ?
I'll try to reconfigure the instance focusing more in testing it (both local and remote) and I'll post the results here.

I've been facing the unauthorized issue with every save from ParseCloud. Using @simonbengtsson tip to include serverUrl during app initialization worked for me.

@leo-one Definitely worth a shot trying locally! If that doesn't work, could you post the status code of the http request?

Hi, we are having this same issue. In our case, using either object.fetch() or query.get(object.id) is failing on parse-server v2.1.2 with an error: XMLHttpRequest failed: "Unable to connect to the Parse API" (100)

Work around is to explicitly set the Parse.serverURL _within_ the Cloud code.

cloud/main.js

Parse.Cloud.afterSave("ObjectName", function(request) {
    Parse.serverURL = 'https://appname.herokuapp.com/1';
    exampleObj.fetch({ sessionToken: user_token }).then(function(exampleObj) {
    ....

are you passing the serverURL property to the ParseServer initialization? That's pretty important now..

@simonbengtsson I am trying it locally and I created an Message via REST Api. I noticed that the error occurs here:

// middleware.js, line 90, function handleParseHeaders(req, res, next)
// Client keys are not required in parse-server, but if any have been configured in the server, validate them
  //  to preserve original behaviour
var keyRequired = req.config.clientKey || req.config.javascriptKey || req.config.dotNetKey || req.config.restAPIKey;
  var keyHandled = false;
  if (keyRequired && (info.clientKey && req.config.clientKey && info.clientKey === req.config.clientKey || info.javascriptKey && req.config.javascriptKey && info.javascriptKey === req.config.javascriptKey || info.dotNetKey && req.config.dotNetKey && info.dotNetKey === req.config.dotNetKey || info.restAPIKey && req.config.restAPIKey && info.restAPIKey === req.config.restAPIKey)) {
    keyHandled = true;
  }
  console.log("keyRequired: " + keyRequired);
  console.log("keyHandled: " + keyHandled);
  if (keyRequired && !keyHandled) {
    return invalidRequest(req, res);
  }

Then tried to include X-Parse-Client-Key in the request header (same value that is passed to server in index.js) and it does not work.
Then I removed the client key in the server initialisation (the code clientKey: process.env.CLIENT_KEY || '',) and it worked !!!

The problem is to set the client_key. Even the swift SDK is not sending client key (please see below), neither the client key in REST API request header has worked.

Is this the expected behaviour ?

Headers : ["X-Parse-Installation-Id": "4fop473b-c46d-4951-bf3w-c945ff027748", "X-Parse-Session-Token": "r:8bd43330d81aa37446b2cf0361222bcf", "Content-Type": "application/json; charset=utf-8"]
Request Body : "{\"content\":\"Hello\",\"userId\":\"ad4bvIlGYW\", ... }"

Just confirming: after removing client_key from Parser Server configuration, everything has worked well (including the triggers). I tested from REST API and Swift SDK.

Glad you solved it however that sounds strange. I have been using the ios sdk with parse server and recently checked the http logs for other purposes and it did send the X-Parse-Client-Key. In the middleware function, did you make sure info.clientKey and req.config.clientKey had the same value?

@gfosco had commented above that client key should be removed.
Is it the correct approach or a quick fix?

The Swift SDK adds to header just "X-Parse-Installation-Id" and the "X-Parse-Session-Token", not the "X-Parse-Application-Id" nor "X-Parse-Client-Key".
I will check the values of info.clientKey and req.config.clientKey and post here.

I added a clientKey to my project now and got the same problem. The iOS SDK did send the client key header though so it initially worked. However when I made a request in cloud cloud the internal javascript sdk in parse-server only sent the javascript key (which makes sense I guess). This failed the checks and resulted in the unauthorized error. I think this is a bug in parse-server so for now at least it seems safest to remove any keys but the masterKey. I also don't see any use case for client keys in parse-server so I think that the following checks should simply be removed.

// middlewares.js::102
var keyRequired = (req.config.clientKey
  || req.config.javascriptKey
  || req.config.dotNetKey
  || req.config.restAPIKey);
var keyHandled = false;
if (keyRequired
  && ((info.clientKey && req.config.clientKey && info.clientKey === req.config.clientKey)
    || (info.javascriptKey && req.config.javascriptKey && info.javascriptKey === req.config.javascriptKey)
    || (info.dotNetKey && req.config.dotNetKey && info.dotNetKey === req.config.dotNetKey)
    || (info.restAPIKey && req.config.restAPIKey && info.restAPIKey === req.config.restAPIKey)
  )) {
  keyHandled = true;
}
if (keyRequired && !keyHandled) {
  return invalidRequest(req, res);
}

@leo-one Do you see any use case for client keys? Or do you think it makes sense to simply remove the checks which in effect means removing client keys completely from parse-server?

I am using following curl request to access cloud code hello function.

curl -X POST
-H "X-Parse-Application-Id: dsds_}"
-H "X-Parse-REST-API-Key: asd
_"
-H "Content-Type: application/json"
-d '{}'
http://baseurl**.compute.amazons.com/parse/functions/hello

i tried adding server url in server.js file
i also removed client key from index.js

what else could be the reason?

Try sending the request without the rest key header. And you also have a } trailing your app id, is that intentional? What is the exact error and what is the http status code you get?

@simonbengtsson Thanks it was issue with } this mistake. by mistake that was added here and i didn't notice that.
It solved my problem.

Reopening since the issue solved in the most recent comment wasn't the original issue

@simonbengtsson removing the keys leaving only the masterKey would give any client/user basically the right do dump your database and erase everything. That is why the client keys.
Then the different client keys also allows to know which SDK do what.

It seems that the ParseSDK is wrongly initialized in CloudCode when the request comes from another SDK.

Let me have a look.

the logic here is also wrong:

``````
if (results.length > 0) {
response.success();
} else {
response.error("A Message with this uniqueCode already exists.");
}

``` 
``````

Yes, it was wrong. I had fixed it.
But the problem occurs before this logic.
When the client key is set, any query.find() in Parse Cloud throws unauthorized.

I meant removing the client keys concept from parse server, leaving only the master key (for none client use). As the client keys are public I don't see what difference it would make simply not sending them? That you can see which sdk made the request is valid point I guess, but wouldn't it make more sense that the sdk sent an X-Parse-SDK: javascript header or similar for such purpose?

That's another debate. I've created unit tests for JSSDK, rest and calls with the client key and all are good on my side.

https://github.com/flovilmart/parse-server/blob/troubleshoot356.spec.js/spec/troubleshoot356.spec.js

and:

https://github.com/flovilmart/parse-server/blob/troubleshoot356.spec.js/spec/cloud/main.js

I'm also in favor of doing our best to pretend Client keys don't exist. We will still need to use them in some places (Access-Control-Allow-Headers comes to mind) but we can probably ignore them everywhere else.

Just thought of something, try to init your parse server with a javascriptKey, cloud code needs it to 'authenticate' with the parse server, when the request is sent, if the javascriptKey is not provided, that could be problematic.

Also, does the query work in your case with {useMasterKey: true}?

I just run the tests locally, the problem comes from the Javascript key that is required to make calls inside cloud code. The current workaround is to set the javascript key (to anything) you like in the ParseServer configuration, even if you're not using it.

I'll be working on a fix.
We didn't catch that in the unit tests as we initialize with all the keys all the times.

@leo-one @simonbengtsson check the PR branch, let me know if it still occurs on that branch.

I was having similar issue, "unauthorized", or query constraints not functioning properly. I had all the latest versions of the SDK's and parse-server - OR SO I THOUGHT. I had run all the commands to update the server and it said [email protected]. Then I started learning a little about node and ran some check commands like npm list and low and behold, some how in the list was [email protected]. I uninstalled parse-server anywhere I could find it (may have been more then one) re installed parse-server ran npm list it showed 2.1.2 and just like that everything worked. No more unauthorized, queries worked etc. I don't have any client key (JS, rest, etc) set. In the PHP initializer for the restKey I just set it to "notUsed" because you need 3 and it works like a charm. Not sure if this will help but I can begin to tell you how happy it made me for this to work.

@flovilmart Nope that fixes it! At least for the small test case I used (similar to what you tested I guess).

Awesome!

let us know if it reappears

Hello Friends,

I'm also getting similar "unauthorized" error. I've deployed parse on heroku. I'm successfully able to call the hello cloud function but when try to query on database I'm getting following errors.

{
  "code": 141,
  "error": {
    "message": "unauthorized"
  }
}

This is my code :

Parse.Cloud.define("addToCart", function(request, response)
{                  
    var products = request.params.products;

    var Cart = new Parse.Object.extend("Cart");
    var StoreProducts = new Parse.Object.extend("StoreProducts"); 
    var Products = new Parse.Object.extend("Products"); 
    var Store = new Parse.Object.extend("Store");     


    var userObjectId = request.params.objectId;

    var userPointer = {
      __type: 'Pointer',
      className: '_User',
      objectId: userObjectId
    }

    var cartQuery = new Parse.Query(Cart);
    cartQuery.equalTo('userId',userPointer);

    cartQuery.find({
        success : function(cartData) 
        {
            response.success("Hello addToCart");

            if(carData.length == 1){
                cartData.set("cartProducts",products);
                cartData.save();
            }
        },
        error : function(error)
        {
            response.error(error);
        }

    });

});

Any help/assistance will be highly appreciated. Thank you in advance.

Are you setting up parse-server with any client keys? If so try removing them. If that doesn't work, post your parse server config here.

Hi @simonbengtsson, Thank you for your reply.
I'm using heroku configuration to deploy parse. I've not set any client keys.

var express = require('express');
var ParseServer = require('parse-server').ParseServer;

var databaseUri = process.env.DATABASE_URI || process.env.MONGOLAB_URI;

if (!databaseUri) {
  console.log('DATABASE_URI not specified, falling back to localhost.');
}

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',
  masterKey: process.env.MASTER_KEY || '' //Add your master key here. Keep it secret!
});

Do you need any other information to provide your assistance ?

Thank you very much again !!

add the serverUrl option to the ParseServer initialization. serverUrl: 'https://myappname.herokuapp.com/parse'

Hi @gfosco @simonbengtsson
Thank you for your reply.

I've added serverUrl option l in ParseServer initialization.

var api = new ParseServer({
  databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  serverUrl: 'https://myapp-dev.herokuapp.com/parse',
  appId: process.env.APP_ID || 'myAppId',
  masterKey: process.env.MASTER_KEY || '' //Add your master key here. Keep it secret!
});

When I execute following simple cloud function that save document in collection, I'm getting same "unauthorized" error.

Parse.Cloud.define('addToGameScore', function(req, res) {

    var GameScore = Parse.Object.extend("GameScore");

    var gameScore = new GameScore();

    gameScore.set("score", 1387);
    gameScore.set("playerName", "Sean Plott");
    gameScore.set("cheatMode", false);
    gameScore.set("skills", ["pwnage", "flying"]);

    gameScore.save(null, {
        success: function(gameScore) {
            res.success("IamSavedInDatabase");
        },
        error: function(gameScore,error){
            res.error(error);
        }
    });

});

I'm calling "addToGameScore" function from Postman/Curl.

I think still I'm missing some configuration.

Thank you for continous assistance.

Hi All,

I have created new parse app on heroku and issue resolved !!!!

Thank you all for your assistance and guidance.

HELLO GUY . I NEED HELP PLEASE
03-24 20:09:45.769 3376-3490/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:10:48.493 3544-3564/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:10:48.502 3544-3566/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:10:50.492 3544-3574/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:10:50.510 3544-3575/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:10:54.041 3544-3578/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:10:54.071 3544-3580/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:11:00.782 3544-3583/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:11:00.982 3544-3585/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:11:14.031 3544-3589/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:11:14.551 3544-3592/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:11:15.181 3544-3544/? I/Parse: Save Failed
03-24 20:13:45.070 3635-3652/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:13:45.100 3635-3654/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:13:47.204 3635-3662/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:13:47.665 3635-3664/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:13:50.472 3635-3666/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:13:50.774 3635-3668/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:13:55.775 3635-3671/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:13:57.643 3635-3674/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:14:06.025 3635-3676/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:14:11.264 3635-3680/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:14:11.664 3635-3635/? I/Parse: Save Failed
03-24 20:15:51.784 3765-3782/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:15:51.811 3765-3784/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:15:53.266 3765-3793/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:15:54.997 3765-3795/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:15:55.687 3765-3798/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:15:58.777 3765-3800/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:16:00.347 3765-3803/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:16:06.074 3765-3805/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:16:09.306 3765-3808/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:16:20.376 3765-3813/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:16:20.615 3765-3765/? I/Parse: Save Failed
03-24 20:19:03.954 3857-3873/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:19:03.984 3857-3876/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:19:06.399 3857-3884/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:19:06.820 3857-3886/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:19:09.977 3857-3888/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:19:10.761 3857-3891/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:19:15.978 3857-3893/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:19:18.451 3929-3946/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:19:18.502 3929-3949/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:19:20.180 3929-3955/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:19:20.550 3929-3957/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:19:23.029 3929-3960/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:19:24.200 3929-3963/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:19:28.469 3929-3965/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:19:31.390 3929-3968/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:19:39.159 3929-3971/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 20:19:39.479 3929-3929/? I/Parse: Save Failed
03-24 20:19:45.389 3929-3975/? W/System: Ignoring header X-Parse-Client-Key because its value was null.

// Enable Local Datastore.
Parse.enableLocalDatastore(this);

// Add your initialization code here
Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
                .applicationId("verokiiopkohgtndkop")
                .clientKey(null)
                .server("https://jffuhvbjknfxggjfgfifgjgjxfjhygsgsyg.herokuapp.com/parse/")
.build()
);

  ParseObject gameScore = new ParseObject("GameScore");
  gameScore.put("score", 1337);
  gameScore.put("playerName", "Sean Plott");
  gameScore.put("cheatMode", false);
  gameScore.saveInBackground(new SaveCallback() {
      public void done(ParseException e) {
          if (e == null) {
              Log.i("Parse", "Save Succeeded");
          } else {
              Log.i("Parse", "Save Failed")

PLEASE LET ME KNOW HOW I CAN FIX THIS BECAUSE I SPEND 4 DAYS IN IT . I CANT FIX IT

You're explicitly setting the client key to a null value in that code..
Change it to literally any string like 'clientKeyIsNotUsed' and it should
stop telling you that.

On Thursday, March 24, 2016, eustache509 [email protected] wrote:

PLEASE LET ME KNOW HOW I CAN FIX THIS BECAUSE I SPEND 4 DAYS IN IT . I
CANT FIX IT

—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/ParsePlatform/parse-server/issues/356#issuecomment-201121014

Thanks Fosco but it save still fail

03-24 21:23:40.048 4014-4628/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 21:23:40.290 4014-4633/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 21:23:41.707 4014-4634/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 21:23:44.327 4014-4636/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 21:23:49.207 4014-4639/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 21:23:58.707 4014-4642/? W/System: Ignoring header X-Parse-Client-Key because its value was null.
03-24 21:34:19.855 4698-4698/? I/Parse: Save Failed
03-24 21:36:16.718 4791-4791/? I/Parse: Save Failed

@Override
public void onCreate() {
super.onCreate();

// Enable Local Datastore.
Parse.enableLocalDatastore(this);

// Add your initialization code here
Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
                .applicationId("verokiiopkohgtndkop")
                .clientKey("clientkeyHdjsbaudofuinsjdsdghhjd")
                .server("https://jffuhvbjknfxggjfgfifgjgjxfjhygsgsyg.herokuapp.com/parse/")
.build()
);

03-25 00:44:10.737 1300-1300/? W/PackageParser: Ignoring duplicate uses-permissions/uses-permissions-sdk-m: android.permission.INSTALL_GRANT_RUNTIME_PERMISSIONS in package: com.android.shell at: Binary XML file line #101
03-25 00:44:10.787 1300-1300/? W/PackageParser: Ignoring duplicate uses-permissions/uses-permissions-sdk-m: android.permission.CONFIGURE_WIFI_DISPLAY in package: com.android.systemui at: Binary XML file line #119
03-25 00:44:11.266 1300-1300/? W/PackageParser: Ignoring duplicate uses-permissions/uses-permissions-sdk-m: android.permission.WRITE_CONTACTS in package: com.android.email at: Binary XML file line #40
03-25 00:44:11.827 1300-1300/? W/PackageParser: Ignoring duplicate uses-permissions/uses-permissions-sdk-m: android.permission.WAKE_LOCK in package: com.google.android.apps.maps at: Binary XML file line #96
03-25 00:44:12.362 1300-1300/? W/PackageParser: No actions in intent filter at /data/app/ApiDemos/ApiDemos.apk Binary XML file line #3082
03-25 00:44:12.362 1300-1300/? W/PackageParser: No actions in intent filter at /data/app/ApiDemos/ApiDemos.apk Binary XML file line #3088
03-25 00:44:14.607 1300-1300/? W/System.err: at com.android.internal.alsa.AlsaCardsParser.scan(AlsaCardsParser.java:109)
03-25 00:45:10.140 2096-2096/? I/Parse: Save Failed

it give me different message now but , it still save fail

I was having the same issue and initially i though it was the cloud code that needed update. After a lot of troubleshooting I realised that the code was fine. Then I tried to see whether parse server was setup correctly. I am running it on IBM BlueMix (should be the same as heroku). The problem was the following

var parseConfig = { databaseURI: databaseUri, appId: process.env.APP_ID, masterKey: process.env.MASTER_KEY, cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js', serverURL: ((process.env.HTTPS) ? 'https' : 'http') + host + ':' + port + mountPath, };

The server url was resolving to "http0.0.0.0:61026/parse", which was incorrect. I updated it to include :// and the problem was resolved. The new configuration looked like the following:

var parseConfig = { databaseURI: databaseUri, appId: process.env.APP_ID, masterKey: process.env.MASTER_KEY, cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js', serverURL: ((process.env.HTTPS) ? 'https://' : 'http://') + host + ':' + port + mountPath, };

Such a simple mistake took me 4 hours to resolve.

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var path = require('path');

var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;

if (!databaseUri) {
console.log('DATABASE_URI not specified, falling back to localhost.');
}

var api = new ParseServer({
databaseURI: databaseUri || 'mlaburi',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'APPID',
masterKey: process.env.MASTER_KEY || 'MASTER_KEY', //Add your master key here. Keep it secret!,
clientKey:process.env.CLIENT_KEY || 'CLIENT_KEY', //Add you client key here. Keep it secret!,
fileKey:process.env.FILE_KEY || 'FILE_KEY', // Add you file key here,
serverURL: process.env.SERVER_URL || 'https://myappname.herokuapp.com/parse', // Don't forget to change to https if needed
liveQuery: {
classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
}
});

Parse.Cloud.define("articles", function(request, response) {
var query = new Parse.Query("Classname");
query.equalTo("name", "rajesh");
query.find({
success: function(results) {
console.log("sucess experts is",results);
response.success(results);
},
error: function(error) {
console.log("error at expert",error);
response.error("expert failed");
}
});
});
It gives following error
ParseError { code: undefined, message: 'unauthorized' }
Error: {"code":141,"message":"failed"}

@wellkeptbeauty can you open a new issue with detailed informations? Your issue is most likely an implementation issue and not a Parse-server issue.

@flovilmart I ran into this issue today for some reason.

I used the parse-server-example fresh out of the box added restAPIKey: 'rest' and got error unauthorized using cloud code.

You can fix this by adding javascriptKey: 'unused' or pass in clientKey, dotNetKey, restAPIKey to be undefined.

The issue lies with this line

https://github.com/parse-community/parse-server/blob/master/src/middlewares.js#L19

var info = {
    appId: req.get('X-Parse-Application-Id'),
    sessionToken: req.get('X-Parse-Session-Token'),
    masterKey: req.get('X-Parse-Master-Key'),
    installationId: req.get('X-Parse-Installation-Id'),
    clientKey: req.get('X-Parse-Client-Key'),
    javascriptKey: req.get('X-Parse-Javascript-Key'),
    dotNetKey: req.get('X-Parse-Windows-Key'),
    restAPIKey: req.get('X-Parse-REST-API-Key'),
    clientVersion: req.get('X-Parse-Client-Version')
  };

req.get() is returning undefined but info has some defaults

{ appId: 'myAppId',
  sessionToken: undefined,
  masterKey: undefined,
  installationId: 'fbfa62c3-d753-2059-53b2-b6f1e2578b94',
  clientKey: undefined,
  javascriptKey: 'unused', // if your javascriptKey is 'unused' cloud code will always run
  dotNetKey: undefined,
  restAPIKey: undefined,
  clientVersion: 'js1.9.2',
  clientSDK: { sdk: 'js', version: '1.9.2' }

any solution please

Did you check @dplewis response?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LtrDan picture LtrDan  Â·  4Comments

ugo-geronimo picture ugo-geronimo  Â·  3Comments

dpaid picture dpaid  Â·  3Comments

mohmagdy picture mohmagdy  Â·  3Comments

kilabyte picture kilabyte  Â·  4Comments