Rick O'Connor
Posts: 0
Joined: Fri Apr 11, 2014 1:39 pm

JSON Push Notification with XHR.send

Hi guys,

I'm trying to send push notifications through server code but I'm getting a 400 response. Could someone please take a look at the code below. Thanks!

code
var pushApiKey = "6b32xxxxxxxxxxxxxxxxxxxxx95f5a&quot

Code: Select all

 var XHRResponse = XHR.send("POST", "https://api.appery.io/rest/push/msg", { 

         "status": "sent",  

         "headers": { 

           "X-Appery-Push-API-Key": pushApiKey, 
           "Content-Type": "application/json" 

         }, 

         "payload": { 

           "message": "Hello World", 

         }, 

          "filter": { 

           "deviceID": deviceID 

          }     

       }); 

/code

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

JSON Push Notification with XHR.send

Hi Rick,

You have some errors in XHR part.

We're giving you an working code example:
precode
var responseBody = {},
requestParams = {},
paramKeys = request.keys();

for (var key = 0; key < paramKeys&#46;length; key++) {
requestParams[paramKeys[key]] = request&#46;get(paramKeys[key]);
}

&#47;&#47;Fill this value with your goal diviceID&#46;
var deviceID = "356253050022875;e2346ae4310aff98&quot

&#47;&#47;Here is should be your pushApiKey
var pushApiKey = "d8387f9b-d5e3-4cd8-98be-7663f4c956c3&quot

var requestBody = {
"status": "sent",

"payload": {
"message": "Hello World",
},

"filter": {
"deviceID": deviceID
}
};

var request = {

"headers": {

Code: Select all

 "X-Appery-Push-API-Key": pushApiKey, 
 "Content-Type": "application/json" 

},

"body": JSON&#46;stringify(requestBody)

};

var XHRResponse = XHR&#46;send("POST", "https:&#47;&#47;api&#46;appery&#46;io/rest/push/msg", request);

response&#46;success(XHRResponse, "application/json");/code/pre

Also you can send push notification with server code API.
For more info look here: http://docs.appery.io/documentation/b...

Regards.

Return to “Issues”