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")
}
}
}
As Gellert Lee suggested
Did you configure your masterKey in your index.js? masterKey : process.env.MASTER_KEY ||'your masterkey'