Search code examples
javascriptiosparse-platformpush-notificationparse-server

Parse open source server sending push using cloud


I am now on the new parse open source server and I am trying to send a push notification using the cloud main.js. I sent a push using curl but can not in the .js file. Here is the code I have.

Parse.Cloud.define("PushNotification", function(request, response) {
  console.log('sending push');
var Installation = new Parse.Query(Parse.Installation);
  console.log(Installation);

Parse.Push.send({

    where: Installation,
  data: {
    alert: request.params.Message,
    badge: 0,
    sound: 'default'
  }
}, {
  useMasterKey: true,
  success: function() {
    // Push sent!
  console.log('Push sent');
        response.success('success');

  },
  error: function(error) {
    // There was a problem :(
          response.error("Error push did not send");
            console.log('sending push error: '+error);


  }
});

It says that it sent but It did not. If any one could help that would be great!


Solution

  • I got a answer on github and I hope this will help any one else with the same problem. Here is the code I used.

        Parse.Cloud.define("PushNotification", function(request, response) {
          console.log('sending push');
        var Installation = new Parse.Query(Parse.Installation);
          console.log(Installation);
    
        Parse.Push.send({
        useMasterKey: true,
            where: Installation,
          data: {
    //or you can put "" to not do a custom alert
            alert: request.params.Message,
            badge: 0,
            sound: 'default'
          }
        }, {
          useMasterKey: true,
          success: function() {
            // Push sent!
          console.log('Push sent');
                response.success('success');
    
          },
          error: function(error){
        console.error(error);
        }
    
        });
        });