Parse Server Query cannot find user using cloud code

Hello
I have parse server on AWS.
I’m trying to modify existing user through Cloud Code, but I keep getting an error 141. 
The same function works fine from the website.
Basic hello function works just fine in the app.

I’ve run out of ideas what the problem might be

Here is my code:
 

 local toInsert = {["objectId"] = parameter.objectId ,["username"] = val.emailStud} local function onRun( event ) if not event.error then print( "on run ", event.response.value ) else print( "on error ", event.error) end end parse:run( "modifyUser", toInsert, onRun )

And cloud code function:
 

Parse.Cloud.define('modifyUser', function(request, response) { Parse.Cloud.useMasterKey(); var user = new Parse.User(); var query = new Parse.Query(Parse.User); query.equalTo("objectId", request.params.objectId); query.first({ success: function(object) { object.set("username", request.params.username); object.save(); // Set the job's success status response.success("Success Message"); }, error: function(error) { // Set the job's error status response.error(request.params.objectId ); } }); });

This Parse Server right? Not Parse.com.

I’m assuming this in this answer:

Parse.Cloud.useMasterKey(); - this is no longer valid in Parse Server

You need to insert useMasterKey: true, in you query…See below

Parse.Cloud.define(‘modifyUser’, function(request, response) {

var user = new Parse.User();
var query = new Parse.Query(Parse.User);
query.equalTo(“objectId”, request.params.objectId);
query.first({

useMasterKey: true,
success: function(object) {
object.set(“username”, request.params.username);
object.save();
// Set the job’s success status
response.success(“Success Message”);
},
error: function(error) {
// Set the job’s error status
response.error(request.params.objectId );
}
});

});

Thank you for advice!
This may be a thing! I will try it now.

I use AWS hosted parse server.

Quick question: can I just edit main.js file in cloud folder and redeploy the whole app to AWS or cloud code shoul be deployed somehow through terminal in a specific way?

Depends if you have the CLI for deploying the cloud code. If not just copy over the old main.js after modifying.

I use back4app.com for any parse server they have a great interface and its free (oh and it’s hosted on AWS)

oh you will need to change this line as well:

object.save();

to

object.save(null,{useMasterKey: true});

This is because you are modifying a User

Thanks for advice, 
but  I still get the same error. Editing through website works as before.

The problem is not that the user is not saved, but that the query cannot find the user, though the objectId is correct.

Parse.Cloud.define("modifyUser", function(request, response) { var userQuery = new Parse.Query(Parse.User); userQuery.equalTo("objectId", request.params.objectId); userQuery.first ({ useMasterKey: true, success: function(thisuser) { thisuser.set("username",request.params.username); thisuser.save(null, { useMasterKey: true }); response.success("ok"); }, error: function(error) { response.error("failed with error: " + error.message); } }); });

So this is what you should have, I know the save wasn’t part of the question but it was part of the solution because once you solved the finding of the user you would have come back and said that the data is not saving.

Many thanks for your help. 

so with your function I’m getting this error: XMLHttpRequest failed: “Unable to connect to the Parse API”

Not sure if it is progress, but certainly a change.
Thanks again!

[quote name=“patso” post=“349299” timestamp=“1485294696”]Many thanks for your help.  so with your function I’m getting this error: XMLHttpRequest failed: “Unable to connect to the Parse API” Not sure if it is progress, but certainly a change. Thanks again![/quote] That’s nothing to do with the function, that’s a server setup issue, read this thread.https://github.com/ParsePlatform/parse-server/issues/651

Did you install parse server yourself? Try my earlier suggestion try www.back4app.com they take all the configuration problems out of the way.

Hooray. It works. I had to change server Url in AWS configuration to https://www.mydomainame.com/parse and it works fine

Many thanks. 

This is business project I’m working on and we decided that it should directly rely on AWS, so that we won’t need to migrate anymore if the mediator service shuts down like parse.com.
I will definitely use back4app for my own projects, though. Thanks for reference. 

Glad you got it solved :slight_smile:

This Parse Server right? Not Parse.com.

I’m assuming this in this answer:

Parse.Cloud.useMasterKey(); - this is no longer valid in Parse Server

You need to insert useMasterKey: true, in you query…See below

Parse.Cloud.define(‘modifyUser’, function(request, response) {

var user = new Parse.User();
var query = new Parse.Query(Parse.User);
query.equalTo(“objectId”, request.params.objectId);
query.first({

useMasterKey: true,
success: function(object) {
object.set(“username”, request.params.username);
object.save();
// Set the job’s success status
response.success(“Success Message”);
},
error: function(error) {
// Set the job’s error status
response.error(request.params.objectId );
}
});

});

Thank you for advice!
This may be a thing! I will try it now.

I use AWS hosted parse server.

Quick question: can I just edit main.js file in cloud folder and redeploy the whole app to AWS or cloud code shoul be deployed somehow through terminal in a specific way?

Depends if you have the CLI for deploying the cloud code. If not just copy over the old main.js after modifying.

I use back4app.com for any parse server they have a great interface and its free (oh and it’s hosted on AWS)

oh you will need to change this line as well:

object.save();

to

object.save(null,{useMasterKey: true});

This is because you are modifying a User

Thanks for advice, 
but  I still get the same error. Editing through website works as before.

The problem is not that the user is not saved, but that the query cannot find the user, though the objectId is correct.

Parse.Cloud.define("modifyUser", function(request, response) { var userQuery = new Parse.Query(Parse.User); userQuery.equalTo("objectId", request.params.objectId); userQuery.first ({ useMasterKey: true, success: function(thisuser) { thisuser.set("username",request.params.username); thisuser.save(null, { useMasterKey: true }); response.success("ok"); }, error: function(error) { response.error("failed with error: " + error.message); } }); });

So this is what you should have, I know the save wasn’t part of the question but it was part of the solution because once you solved the finding of the user you would have come back and said that the data is not saving.