Naresh Kumar Koppera
Naresh Kumar Koppera

Reputation: 417

Sending Push Notification using javaScript in Parse

Actually we are done with sending push notification from mobile to mobile & parse to mobile using parse quires. Now we are trying to send push notification from web application to mobile device using Javascript.

 function authentication() {

  Parse.$ = jQuery;

  // Initialize Parse with your Parse application javascript keys
  Parse.initialize("app key",
                   "javascript key");

    Parse.Push.send({
          //where: pushQuery,
          channels: [ "Demo","Done" ],
          data: {
          alert : "Hello word" 
    }}, { success: function() {
          // Push was successful 
          alert : "Push was successful"
        //  debugger;
        },
          error: function(error) {


        }}).then (function(error) {
          //Marks this promise as fulfilled, 
          //firing any callbacks waiting on it.


        });


}

Plz Guide us,we are new to javascript. we getting error like this

POST https://api.parse.com/1/push 400 (Bad Request)

Upvotes: 2

Views: 1477

Answers (2)

user3552206
user3552206

Reputation: 156

I am also sending the notification from javascript to Mobile using parse.

My code is almost similar to you except one thing,

Instead of this

Parse.initialize("app key",
                   "javascript key");

I am using

Parse.initialize("APP_ID", "API_KEY", "JAVASCRIPT KEY");

My complete code is.. though I am using node.js you can relate to corresponding code.

var query = new Parse.Query(Parse.Installation);
                   query.equalTo('installationId', parseInstallationId);

                      Parse.Push.send({
                        where: query, // Set our Installation query
                        data: {
                          alert: "Willie Hayes injured by own pop fly." 
                        }
                      }, {
                        success: function() {
                          // Push was successful
                          console.log('successful');
                        },
                        error: function(error) {
                          // Handle error
                          console.log('error');
                        }
                });

Upvotes: 0

PE Cheriere
PE Cheriere

Reputation: 61

Did you activate Client Push Enabled in the Push Notifications settings of your Parse app ?

However, if you decide to send notifications from the JavaScript SDK outside of Cloud Code or any of the other client SDKs, you will need to set Client Push Enabled in the Push Notifications settings of your Parse app.

From: https://parse.com/docs/js/guide#push-notifications-sending-pushes

Note that you shouldn't send notification from any clients, instead trigger the notifications from cloud code

However, be sure you understand that enabling Client Push can lead to a security vulnerability in your app, as outlined on our blog. We recommend that you enable Client Push for testing purposes only, and move your push notification logic into Cloud Code when your app is ready to go into production.

Upvotes: 1

Related Questions