Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query in Parse Cloud returns "unauthorized" error #356

Closed
leonardojobim opened this issue Feb 11, 2016 · 67 comments
Closed

Query in Parse Cloud returns "unauthorized" error #356

leonardojobim opened this issue Feb 11, 2016 · 67 comments
Labels
type:question Support or code-level question

Comments

@leonardojobim
Copy link

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);
            }
        });
    }
});
@gfosco
Copy link
Contributor

gfosco commented Feb 11, 2016

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.

@leonardojobim
Copy link
Author

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

@gfosco
Copy link
Contributor

gfosco commented Feb 11, 2016

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

@leonardojobim
Copy link
Author

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.

@simonbengtsson
Copy link
Contributor

simonbengtsson commented Feb 11, 2016

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?

@simonbengtsson
Copy link
Contributor

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'
}));

@leonardojobim
Copy link
Author

@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.

@leonardojobim
Copy link
Author

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 ?

@simonbengtsson
Copy link
Contributor

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.

@tanmays
Copy link

tanmays commented Feb 12, 2016

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

@jamiechapman
Copy link

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"}}

@simonbengtsson
Copy link
Contributor

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

@jamiechapman
Copy link

@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)

@jamiechapman
Copy link

@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! 👍

@leonardojobim
Copy link
Author

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.

@simonbengtsson
Copy link
Contributor

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?

@leonardojobim
Copy link
Author

@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: #407

@leonardojobim
Copy link
Author

@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.

@simonbengtsson
Copy link
Contributor

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_

@leonardojobim
Copy link
Author

@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.

@chriscborg
Copy link
Contributor

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

@simonbengtsson
Copy link
Contributor

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

@moflo
Copy link

moflo commented Feb 20, 2016

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) {
    ....

@gfosco
Copy link
Contributor

gfosco commented Feb 20, 2016

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

@leonardojobim
Copy link
Author

@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\", ... }"

@leonardojobim
Copy link
Author

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.

@flovilmart
Copy link
Contributor

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

@petek157
Copy link

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 parse-server@2.1.2. 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 parse-server@2.0.0. 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.

@simonbengtsson
Copy link
Contributor

simonbengtsson commented Feb 26, 2016

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

@flovilmart
Copy link
Contributor

Awesome!

@flovilmart
Copy link
Contributor

let us know if it reappears

@jaydeep82
Copy link

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.

@simonbengtsson
Copy link
Contributor

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.

@jaydeep82
Copy link

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 !!

@gfosco
Copy link
Contributor

gfosco commented Feb 26, 2016

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

@jaydeep82
Copy link

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.

@jaydeep82
Copy link

Hi All,

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

Thank you all for your assistance and guidance.

@eustache509
Copy link

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.

@eustache509
Copy link

// 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")

@eustache509
Copy link

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

@gfosco
Copy link
Contributor

gfosco commented Mar 25, 2016

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 notifications@github.com 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
#356 (comment)

@eustache509
Copy link

Thanks Fosco but it save still fail

@eustache509
Copy link

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

@eustache509
Copy link

@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()
);

@eustache509
Copy link

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

@eustache509
Copy link

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

@zirinisp
Copy link

zirinisp commented Sep 8, 2016

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.

@wellkeptbeauty
Copy link

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"}

@flovilmart
Copy link
Contributor

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

@dplewis
Copy link
Member

dplewis commented Jun 16, 2017

@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' }

@drmark1989
Copy link

any solution please

@flovilmart
Copy link
Contributor

Did you check @dplewis response?

@mtrezza mtrezza added type:question Support or code-level question and removed 🔧 troubleshooting labels Jul 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question Support or code-level question
Projects
None yet
Development

No branches or pull requests