0
votes

Whenever I try to run this snippet of cloud code, I receive an error stating that:

Error generating response. ParseError { code: 141, message: 'Push failed to send with error: master key is required'}

I've tried to follow some of the other solutions on the site such as using Parse.Cloud.useMasterKey() & useMasterKey: true but I haven't found success with any of these commands (possibly due to me using them incorrectly?).

Parse.Cloud.define("sendPushToUser", function(request, response) {

    var senderUser = request.user;
    var recipientUserId = request.params.recipientId;
    var message = request.params.message;

    var recipientUser = new Parse.User();
    recipientUser.id = recipientUserId;
    var pushQuery = new Parse.Query(Parse.Installation);
    pushQuery.equalTo("user", recipientUser);

    Parse.Push.send({
            where: pushQuery,
            data: {
                    alert: message
            }
    }).then(function() {
            response.success("Push was sent successfully.")
    }, function(error) {
            response.error("Push failed to send with error: " + error.message);
    });
});

Swift function:

func testPush() {



    PFCloud.callFunction(inBackground: "sendPushToUser", withParameters: ["recipientId": PFUser.current()?.objectId!, "message" : "Test notification"]) { (success, error) in
        if error != nil {
            print("error occurred")
        }else {
            print("Sent successfully")
        }
    }
}
1
How/where are you running it from? The error exists on the client side - OneCricketeer
I'm running it from my swift application. The error is present on the Parse dashboard logs and is returned as an error message when I try to activate it via my app. - Gabe
Edited the original question just now. Sorry about that. - Gabe
It's been awhile since using Parse, but I remember that Cloud code should allow you to to pushes no problem, and it seems your error is thinking you are trying to send a push from the swift code itself. - OneCricketeer
Did you configure your masterKey in your index.js? masterKey : process.env.MASTER_KEY ||'your masterkey' - One Eyed Raven

1 Answers

0
votes

As Gellert Lee suggested

Did you configure your masterKey in your index.js? masterKey : process.env.MASTER_KEY ||'your masterkey'